public function actionModel($table) { if (!ConsoleApp::get()->sql()->tableExists($table)) { $this->error("Table `{$table}` not found!"); if (!($table = $this->similarTables($table))) { return; } } $className = str_replace(' ', '', ucwords(str_replace('_', ' ', $table))); $className = Helper::get()->input("Class name", $className); $this->info("Selected class: {$className}"); $columns = ConsoleApp::get()->sql()->getTableColumns($table); $modelInfo = array('table' => $table, 'class' => $className, 'namespace' => Helper::get()->input("Namespace", 'app\\models'), 'columns' => array(), 'labels' => array()); echo "Labels (found " . count($columns) . " columns): \n"; foreach ($columns as $column) { $modelInfo['columns'][$column['Field']] = $column['Type']; $modelInfo['labels'][$column['Field']] = Helper::get()->input($column['Field'], ucwords(str_replace('_', ' ', $column['Field']))); } if ('Y' == strtoupper(Helper::get()->input('Add relations? (y/n)', 'y'))) { $modelInfo['relations'] = array(); do { $name = ''; while (!$name) { $name = Helper::get()->input('Name'); } $type = 0; while (!$type) { $type = Helper::get()->input('Types [1] : BELONGS_TO [2] : HAS_ONE [3] : HAS_MANY [4] : MANY_TO_MANY Selected type'); } $model = ''; $classError = false; while (!$model || ($classError = !class_exists($model))) { if ($classError) { $this->error('Class "' . $model . '" not found!'); $classError = false; } $model = Helper::get()->input('Model class'); } $connection = ''; while (!$connection) { $connection = Helper::get()->input('Connection'); } $modelInfo['relations'][] = array('name' => $name, 'type' => $type, 'model' => $model, 'connection' => $connection); } while ('y' == Helper::get()->input('Add more? (y/n)', 'y')); } $creator = new Creator($modelInfo); if ($creator->model()) { $this->debug('model created!'); } }
* * MPF Framework is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * MPF Framework is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with MPF Framework. If not, see <http://www.gnu.org/licenses/>. */ define('LIBS_FOLDER', dirname(__DIR__) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR); define('APP_ROOT', __DIR__ . DIRECTORY_SEPARATOR); /** * Set ErrorException for every error; */ set_error_handler(function ($errno, $errstr, $errfile, $errline) { $severity = 1 * E_ERROR | 1 * E_WARNING | 1 * E_PARSE | 1 * E_NOTICE | 0 * E_CORE_ERROR | 0 * E_CORE_WARNING | 0 * E_COMPILE_ERROR | 0 * E_COMPILE_WARNING | 1 * E_USER_ERROR | 1 * E_USER_WARNING | 1 * E_USER_NOTICE | 0 * E_STRICT | 0 * E_RECOVERABLE_ERROR | 0 * E_DEPRECATED | 0 * E_USER_DEPRECATED; $ex = new \ErrorException($errstr, 0, $errno, $errfile, $errline); if (($ex->getSeverity() & $severity) != 0) { \mpf\ConsoleApp::get()->error($errstr, array('File' => $errfile, 'Line' => $errline, 'Number' => $errno, 'Trace' => $ex->getTraceAsString())); } }); $autoload = (require_once LIBS_FOLDER . 'autoload.php'); use mpf\ConsoleApp as App; use mpf\base\Config; new Config(APP_ROOT . 'config' . DIRECTORY_SEPARATOR . 'console.inc.php'); App::run(array('startTime' => microtime(true), 'autoload' => $autoload));
/** * Get namespace for commands; * @return string */ protected function getNameSpace() { return '\\app\\' . \mpf\ConsoleApp::get()->commandsNamespace . '\\'; }