function create_demo() { $db_line = color(str_repeat('=', 80), 'N') . "\n"; $line = color(str_repeat('-', 80), 'w') . "\n"; echo $db_line; $results = array(); $migrations = array('event' => array(), 'attendee' => array(), 'tag' => array(), 'tag_event_map' => array()); array_walk($migrations, function ($value, $key) use(&$results) { array_push($results, implode("\n", array_map(function ($result) { $count = 1; return color(' Create: ', 'g') . str_replace(FCPATH, '', $result, $count); }, create_migration(BASEPATH . 'cmd/templates/demo/' . $key . '/', $key, 'add')))); }); echo implode("\n", $results) . "\n" . $line; $results = array(); $models = array('event' => array('-p' => array('cover')), 'attendee' => array(), 'tag' => array(), 'tag_event_map' => array()); array_walk($models, function ($value, $key) use(&$results) { array_push($results, implode("\n", array_map(function ($result) { $count = 1; return color(' Create: ', 'g') . str_replace(FCPATH, '', $result, $count); }, create_model(BASEPATH . 'cmd/templates/demo/' . $key . '/', $key, isset($value['-p']) ? $value['-p'] : array(), isset($value['-f']) ? $value['-f'] : array())))); }); echo implode("\n", $results) . "\n" . $line; $results = array(); $cells = array('demo' => array('main_menu')); array_walk($cells, function ($value, $key) use(&$results) { array_push($results, implode("\n", array_map(function ($result) { $count = 1; return color(' Create: ', 'g') . str_replace(FCPATH, '', $result, $count); }, create_cell(BASEPATH . 'cmd/templates/demo/cell/', $key, $value)))); }); echo implode("\n", $results) . "\n" . $line; $results = array(); $controllers = array('events' => array(), 'tags' => array()); array_walk($controllers, function ($value, $key) use(&$results) { array_push($results, implode("\n", array_map(function ($result) { $count = 1; return color(' Create: ', 'g') . str_replace(FCPATH, '', $result, $count); }, create_controller(BASEPATH . 'cmd/templates/demo/' . singularize($key) . '/', $key, 'site', array('index', 'show', 'add', 'create', 'edit', 'update', 'destroy'))))); }); echo implode("\n", $results) . "\n" . $line; $results = run_migration(null); echo color('注意! ', 'r'); echo implode("\n", $results) . "\n"; $results = array(); array_push($results, "migrations(" . implode(', ', array_keys($migrations)) . ")"); array_push($results, "models(" . implode(', ', array_keys($models)) . ")"); array_push($results, "cells(" . implode(', ', array_keys($cells)) . ")"); array_push($results, "controllers(" . implode(', ', array_keys($controllers)) . ")"); return $results; }
function create_model($opts) { $filename = filename($opts[0]); $text = <<<MODEL <?php class {$filename} extends Model { const TABLE = "{$opts['0']}"; } MODEL; $fh = fopen(APP_ROOT . '/app/models/' . $filename . '.class.php', 'w'); fwrite($fh, $text); fclose($fh); create_migration($opts); }
$file = array_shift($argv); $type = array_shift($argv); $name = array_shift($argv); $action = !in_array(strtolower($type), array('model')) ? array_shift($argv) : $argv; switch (strtolower($type)) { case 'controller': $results = create_controller($temp_path, $name, $action); break; case 'model': $params = params($action, array('-p', '-f', '-pic', '-file')); $images = array_merge($images = isset($params['-p']) ? $params['-p'] : array(), isset($params['-pic']) ? $params['-pic'] : array()); $files = array_merge($files = isset($params['-f']) ? $params['-f'] : array(), isset($params['-file']) ? $params['-file'] : array()); $results = create_model($temp_path, $name, $images, $files); break; case 'migration': $results = create_migration($temp_path, $name, $action); break; case 'cell': $results = create_cell($temp_path, $name, array_merge(array($action), $argv)); break; case 'demo': include 'functions/demo.php'; $results = create_demo(); break; case 'search': $results = create_search($temp_path, $name); break; default: return console_error('指令錯誤!', '只接受 controller、model、migration、cell、demo、search 指令。'); } $results = array_map(function ($result) {