Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
13 / 13 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| AbstractTable | |
100.00% |
13 / 13 |
|
100.00% |
4 / 4 |
6 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| getTable | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getInfo | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| renderToStatements | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
3 | |||
| render | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| __toString | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| 1 | <?php |
| 2 | declare(strict_types=1); |
| 3 | /** |
| 4 | * Pop PHP Framework (https://www.popphp.org/) |
| 5 | * |
| 6 | * @link https://github.com/popphp/popphp-framework |
| 7 | * @author Nick Sagona, III <nick@popphp.org> |
| 8 | * @copyright Copyright (c) 2009-2026 Nick Sagona, III |
| 9 | * @license https://www.popphp.org/license New BSD License |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * @namespace |
| 14 | */ |
| 15 | namespace Pop\Db\Sql\Schema; |
| 16 | |
| 17 | use Pop\Db\Adapter\AbstractAdapter; |
| 18 | use Pop\Db\Sql\AbstractSql; |
| 19 | use Pop\Db\Gateway; |
| 20 | |
| 21 | /** |
| 22 | * Abstract schema table class |
| 23 | * |
| 24 | * @category Pop |
| 25 | * @package Pop\Db |
| 26 | * @author Nick Sagona, III <nick@popphp.org> |
| 27 | * @copyright Copyright (c) 2009-2026 Nick Sagona, III |
| 28 | * @license https://www.popphp.org/license New BSD License |
| 29 | * @version 7.0.0 |
| 30 | */ |
| 31 | abstract class AbstractTable extends AbstractSql |
| 32 | { |
| 33 | |
| 34 | /** |
| 35 | * Table name |
| 36 | * @var ?string |
| 37 | */ |
| 38 | protected ?string $table = null; |
| 39 | |
| 40 | /** |
| 41 | * Table info |
| 42 | * @var array |
| 43 | */ |
| 44 | protected array $info = []; |
| 45 | |
| 46 | /** |
| 47 | * Constructor |
| 48 | * |
| 49 | * Instantiate the table object |
| 50 | * |
| 51 | * @param string $table |
| 52 | * @param AbstractAdapter $db |
| 53 | */ |
| 54 | public function __construct(string $table, AbstractAdapter $db) |
| 55 | { |
| 56 | $this->table = $table; |
| 57 | parent::__construct($db); |
| 58 | |
| 59 | $tableGateway = new Gateway\Table($table); |
| 60 | $this->info = $tableGateway->getTableInfo($db); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Get the table name |
| 65 | * |
| 66 | * @return string |
| 67 | */ |
| 68 | public function getTable(): string |
| 69 | { |
| 70 | return $this->table; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Get the table info |
| 75 | * |
| 76 | * @return array |
| 77 | */ |
| 78 | public function getInfo(): array |
| 79 | { |
| 80 | return $this->info; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Render the table schema to an array of statements |
| 85 | * |
| 86 | * @return array |
| 87 | */ |
| 88 | public function renderToStatements(): array |
| 89 | { |
| 90 | $statements = explode(';' . PHP_EOL, $this->render()); |
| 91 | $sqlStatements = []; |
| 92 | |
| 93 | foreach ($statements as $statement) { |
| 94 | $statement = trim($statement); |
| 95 | if (!empty($statement)) { |
| 96 | $sqlStatements[] = $statement; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | return $sqlStatements; |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Render the table schema |
| 105 | * |
| 106 | * @return string |
| 107 | */ |
| 108 | abstract public function render(): string; |
| 109 | |
| 110 | /** |
| 111 | * Render the table schema to string |
| 112 | * |
| 113 | * @return string |
| 114 | */ |
| 115 | abstract public function __toString(): string; |
| 116 | |
| 117 | } |