From 60060cafcb3024e31b9ebd15b0ec35cd55192e05 Mon Sep 17 00:00:00 2001 From: "Paul M. Jones" Date: Sat, 30 Jun 2018 15:09:20 -0500 Subject: [PATCH] recognize UNSIGNED, and add a Table constant for the PDO driver --- phpunit.xml.dist | 7 ++++++- resources/templates/TypeTable.tpl | 2 ++ src/Skeleton.php | 15 ++++++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index dd0e489..33cc89b 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,7 +1,12 @@ - + tests/ + + + ./src + + diff --git a/resources/templates/TypeTable.tpl b/resources/templates/TypeTable.tpl index 96c376f..0761112 100644 --- a/resources/templates/TypeTable.tpl +++ b/resources/templates/TypeTable.tpl @@ -17,6 +17,8 @@ use Atlas\Table\Table; */ class {TYPE}Table extends Table { + const DRIVER = {DRIVER}; + const NAME = {NAME}; const COLUMNS = {COLUMNS}; diff --git a/src/Skeleton.php b/src/Skeleton.php index 7cce6f0..9c373e3 100644 --- a/src/Skeleton.php +++ b/src/Skeleton.php @@ -187,7 +187,14 @@ protected function getVars(string $type, string $table, array $columns, $sequenc $info .= " '{$col['name']}' => " . var_export($col, true) . ',' . PHP_EOL; - $props .= " * @property mixed \${$col['name']} {$col['type']}"; + $coltype = $col['type']; + $unsigned = ''; + if (substr(strtoupper($coltype), -9) == ' UNSIGNED') { + $unsigned = substr($coltype, -9); + $coltype = substr($coltype, 0, -9); + } + + $props .= " * @property mixed \${$col['name']} {$coltype}"; if ($col['size'] !== null) { $props .= "({$col['size']}"; if ($col['scale'] !== null) { @@ -195,6 +202,9 @@ protected function getVars(string $type, string $table, array $columns, $sequenc } $props .= ')'; } + + $props .= $unsigned; + if ($col['notnull'] === true) { $props .= ' NOT NULL'; } @@ -231,9 +241,12 @@ protected function getVars(string $type, string $table, array $columns, $sequenc $fields = $props; $this->setRelatedFields($type, $fields); + $driver = $this->connection->getDriverName(); + return [ '{NAMESPACE}' => $this->namespace, '{TYPE}' => $type, + '{DRIVER}' => "'{$driver}'", '{NAME}' => "'{$table}'", '{COLUMN_NAMES}' => $cols, '{COLUMN_DEFAULTS}' => $default,