From d03b68e3f02b1e4d2cfa60516c580e6a949960a2 Mon Sep 17 00:00:00 2001 From: WanWizard Date: Mon, 15 May 2017 12:10:27 +0100 Subject: [PATCH] fixed incorrect parsing of column data; closes #253 thanks to @stvowi for the fix --- classes/generate/scaffold.php | 38 ++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/classes/generate/scaffold.php b/classes/generate/scaffold.php index 76992c81..461653c0 100644 --- a/classes/generate/scaffold.php +++ b/classes/generate/scaffold.php @@ -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);