Skip to content

Commit

Permalink
recognize UNSIGNED, and add a Table constant for the PDO driver
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul M. Jones committed Jun 30, 2018
1 parent b4d6dc1 commit 60060ca
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
7 changes: 6 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<phpunit bootstrap="phpunit.php">
<testsuites>
<testsuite>
<testsuite name="atlas/cli">
<directory>tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
</phpunit>
2 changes: 2 additions & 0 deletions resources/templates/TypeTable.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ use Atlas\Table\Table;
*/
class {TYPE}Table extends Table
{
const DRIVER = {DRIVER};

const NAME = {NAME};

const COLUMNS = {COLUMNS};
Expand Down
15 changes: 14 additions & 1 deletion src/Skeleton.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,24 @@ 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) {
$props .= ",{$col['scale']}";
}
$props .= ')';
}

$props .= $unsigned;

if ($col['notnull'] === true) {
$props .= ' NOT NULL';
}
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 60060ca

Please sign in to comment.