Skip to content

Commit

Permalink
fixed incorrect parsing of column data; closes #253
Browse files Browse the repository at this point in the history
thanks to @stvowi for the fix
  • Loading branch information
WanWizard committed May 15, 2017
1 parent 0aa9dd0 commit d03b68e
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions classes/generate/scaffold.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,39 @@ public static function forge($args, $subfolder)
$data['fields'] = array();
foreach (array_slice($args, 1) as $arg)
{
// Parse the argument for each field in a pattern of name:type[constraint]
preg_match(static::$fields_regex, $arg, $matches);
// parse the argument for each field in a pattern of name:type[constraint]
if (is_string($arg))
{
preg_match(static::$fields_regex, $arg, $matches);

if ( ! isset($matches[1]))
{
throw new Exception('Unable to determine the field definition for "'.$arg.'". Ensure they are name:type');
}

$data['fields'][] = array(
'name' => \Str::lower($matches[1]),
'type' => isset($matches[2]) ? $matches[2] : 'string',
'constraint' => isset($matches[4]) ? $matches[4] : null,
);
}

if ( ! isset($matches[1]))
// argument is an array with a column definition
elseif (is_array($arg))
{
throw new Exception('Unable to determine the field definition for "'.$arg.'". Ensure they are name:type');
$data['fields'][] = array(
'name' => $arg['name'],
'type' => $arg['type'],
'constraint' => $arg['constraint'],
);
}

$data['fields'][] = array(
'name' => \Str::lower($matches[1]),
'type' => isset($matches[2]) ? $matches[2] : 'string',
'constraint' => isset($matches[4]) ? $matches[4] : null,
);
// huh?
else
{
// skip it
logger(\Fuel::L_DEBUG, 'Generate_Scaffold::forge(): incorrect argument type passed');
}
}

$name = array_shift($args);
Expand Down

0 comments on commit d03b68e

Please sign in to comment.