foreach ($params as $key) { @(list($key, $type) = explode(':', $key)); $type = $type ?: $columns[$key]['type']; if (!isset($columns[$key])) { $fail = TRUE; error("\n Unknown '{$key}' field\n"); } elseif (!($test = field_for($type, $key))) { $fail = TRUE; error("\n Unknown '{$type}' type on '{$key}' field\n"); } else { $fields[$key] = $test; } } } else { foreach ($columns as $key => $val) { $fields[$key] = field_for($val['type'], $key); } } $pk = $model_class::pk(); foreach (array($pk, 'created_at', 'modified_at') as $tmp) { if (isset($fields[$tmp])) { unset($fields[$tmp]); } } if (!$fail) { if (!$fields) { error("\n Missing fields for '{$name}' crud\n"); } else { require path(__DIR__, 'build_scaffold.php'); } }
<?php $name = array_shift($params); if (!$name or is_bool($name) or strpos($name, ':') !== FALSE) { error("\n Missing model name\n"); } else { $fields = array(); foreach ($params as $i => $one) { if (strpos($one, ':')) { @(list($field, $type) = explode(':', $one)); if (!field_for($type)) { return error("\n Unknown '{$type}' type on '{$field}' field\n"); } else { $fields[$field] = compact('type'); } } } if (!$fields) { error("\n Missing columns for '{$name}' model\n"); } else { $out_file = path(APP_PATH, 'app', 'models', "{$name}.php"); if (arg('t timestamps')) { $fields['created_at'] = $fields['modified_at'] = array('type' => 'timestamp'); } if (!is_file($out_file) or arg('f force')) { $table = arg('n table'); $extends = arg('x extends') ?: 'database'; $conn = arg('c connection') ?: 'default'; $idx = array_filter(explode(',', arg('i indexes'))); add_model($name, $table, $fields, $idx, $extends, $conn); } else {