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