diff --git a/application/module/core/generator/GeneratorController.php b/application/module/core/generator/GeneratorController.php index a4240e0..7643a3a 100755 --- a/application/module/core/generator/GeneratorController.php +++ b/application/module/core/generator/GeneratorController.php @@ -1,75 +1,184 @@ addColumn("name", 'string', Array('null' => false)); + \$table->addColumn("time", 'timestamp', Array('null' => true, 'default'=>null)); + \$table->addColumn("areaid", 'integer', Array('null' => false)); + \$table->addTimestamps(); + \$table->addSoftDelete(); + \$table->create(); + + Migrator::getInstance()->update_plugin_version('{{PLUGIN_NAME}}', '1.0.0'); + return; + } - }; + //if (\$pluginversion < '1.0.1') { + //\$table = Wrapper::get_table('{{PLUGIN_NAME}}'); + //Migrator::getInstance()->update_plugin_version('{{PLUGIN_NAME}}', '1.0.1'); + //return; + //} + } + EOL; + + private $versionBase = + <<name = '{{PLUGIN_NAME}}'; + \$plugin->version = '0.0.1'; + + //\$plugin->require = Array( ["name" => "plugin_name", "version" => 'x.x.x'] ); + EOL; + + private $controllerBase = + <<askText() - ->setPlaceholderText('Enter something here') - ->ask(); + class {{OBJECT}} extends Entity { + + //const _idPolice = Array('type' => '', 'min' => 0, 'max' => 100000, 'step' => 2); + + const _tableName = '{{TABLE_NAME}}'; + //const _properties = Array('id', 'name'); + + //const _timestamps = true; + //const _softdelete = true; + + //const _connectionName = ''; + } + EOL; + + private $routeBase = + <<name_path = $result->fetch(); - $clm->getSelectedItem()->showItemExtra(); - }; + use Routes\RouteCollection as RouteCollection; - $show_info = function(CliMenu $clm) { - $clm->flash('Module name and path \n' . $this->name_path)->display(); - }; - - /* $menu = (new CliMenuBuilder) - ->setTitle(Lang::getString('main_title', 'generator')) - ->addItem(Lang::getString('name_definition', 'generator'), $module_name) - ->addItem(Lang::getString('show_info', 'generator'), $show_info) - ->setItemExtra('[COMPLETE!]') - ->addLineBreak('-') - ->setBorder(1, 2, 'yellow') - ->setPadding(2, 4) - //->setMarginAuto() - ->build(); - - $menu->open(); */ - /* $menu = (new CliMenuBuilder) - ->setTitle('CLI Menu') - ->addItem('First Item', $default_behavior) - ->addItem('Second Item', $default_behavior) - ->addLineBreak('-') - ->addSubMenu('Options', function (CliMenuBuilder $b) { - $b->setTitle('CLI Menu > Options') - ->addItem('First option', function (CliMenu $menu) { - echo sprintf('Executing option: %s', $menu->getSelectedItem()->getText()); - }) - ->addLineBreak('-'); - }) - ->setWidth(70) - ->setBackgroundColour('yellow') - ->build(); - $menu->open(); */ - $callable = function (CliMenu $menu) { - echo "I'm just a boring selectable item"; - }; - - $menu = (new CliMenuBuilder) - ->addItem('Normal Item', function(){}) - ->addSubMenu('Super Sub Menu', function (CliMenuBuilder $b) { - $b->setTitle('Behold the awesomeness') - ->addItem('asdasdasdas', function(){}); - }) - ->build(); - $menu->open(); + RouteCollection::group('/{{PLUGIN_NAME}}', function(){ + RouteCollection::get ('/', '{{CONTROLLER}}@index'); + RouteCollection::get ('/', '{{CONTROLLER}}@create'); + RouteCollection::post ('/', '{{CONTROLLER}}@store'); + RouteCollection::get ('/[i:id]', '{{CONTROLLER}}@show'); + RouteCollection::get ('/[i:id]/edit', '{{CONTROLLER}}@edit'); + RouteCollection::put ('/[i:id]/edit', '{{CONTROLLER}}@update'); + RouteCollection::delete('/[i:id]', '{{CONTROLLER}}@destroy'); + }); + EOL; + + function createPluginFromTemplate($subname, $name){ + if (is_dir( DIR_MODULE.$subname . '/' . $name )){ + echo 'Treco ja existe'; + return; + }else{ + mkdir(DIR_MODULE.$subname . '/' . $name, 0755, true); + mkdir(DIR_MODULE.$subname . '/' . $name . '/lang', 0755, true); + mkdir(DIR_MODULE.$subname . '/' . $name . '/classes', 0755, true); + mkdir(DIR_MODULE.$subname . '/' . $name . '/db', 0755, true); + mkdir(DIR_MODULE.$subname . '/' . $name . '/views', 0755, true); + } + + $plugin_name = $name; + $plugin_name_pretty = ucwords(str_replace('_', ' ', $name)); + $object = ucfirst( $name ); + $controller = $object.'Controller'; + + $this->langBase = str_replace("{{PLUGIN_NAME}}", $plugin_name, $this->langBase); + $this->langBase = str_replace("{{PLUGIN_NAME_PRETTY}}", $plugin_name_pretty, $this->langBase); + file_put_contents(DIR_MODULE.$subname . '/' . $name . '/lang/en.php', $this->langBase); + file_put_contents(DIR_MODULE.$subname . '/' . $name . '/lang/'.APP_LANG.'.php', $this->langBase); + + $this->migrationBase = str_replace("{{PLUGIN_NAME}}", $plugin_name, $this->migrationBase); + file_put_contents(DIR_MODULE.$subname . '/' . $name . '/db/Migrate.php', $this->migrationBase); + + $this->routeBase = str_replace("{{PLUGIN_NAME}}", $plugin_name, $this->routeBase); + $this->routeBase = str_replace("{{CONTROLLER}}", $controller, $this->routeBase); + file_put_contents(DIR_MODULE.$subname . '/' . $name . '/Routes.php', $this->routeBase); + + $this->objectBase = str_replace("{{OBJECT}}", $object, $this->objectBase); + $this->objectBase = str_replace("{{TABLE_NAME}}", $name, $this->objectBase); + file_put_contents(DIR_MODULE.$subname . '/' . $name . "/classes/$object.php", $this->objectBase); + + $this->controllerBase = str_replace("{{OBJECT}}", $object, $this->controllerBase); + $this->controllerBase = str_replace("{{CONTROLLER}}", $controller, $this->controllerBase); + file_put_contents(DIR_MODULE.$subname . '/' . $name . "/$controller.php", $this->controllerBase); + + } - + + function listRoutes(){ + foreach(RouteCollection::returnRoutes() as $route){ + //var_dump($route->_callback);continue;//die(); + echo implode($route->_verb , ', ') ." || $route->_uri || $route->_weight||"; + if( gettype($route->_callback[0]) == 'object' ){ + echo 'Clousure ||'; + }else{ + echo $route->_callback[0]; + } + echo "\n"; + } + //file_put_contents('/tmp/Route.php', $this->routeBase); + //echo $this->objectBase; + echo APP_LANG; + } + } + diff --git a/application/module/core/generator/Routes.php b/application/module/core/generator/Routes.php index bba3420..60b7027 100755 --- a/application/module/core/generator/Routes.php +++ b/application/module/core/generator/Routes.php @@ -2,24 +2,23 @@ use Routes\RouteCollection as RouteCollection; - -RouteCollection::cli('/core/purge', function(){ - echo "Purging Everything\n"; -}); - -RouteCollection::cli('/core/purge/[h:module]', function($module){ - echo "Purgin $module\n"; -}); - -RouteCollection::cli('/core/routes', function(){ - foreach(RouteCollection::returnRoutes() as $route){ - echo str_pad( implode(',', $route->_verb), 10) . "| $route->_uri \n"; - } -}); - -RouteCollection::cli('/core/generator', function(){ - +RouteCollection::group('/core', function(){ + include_once 'GeneratorController.php'; - last_class()->menu(); + + RouteCollection::cli('/routes', function(){ + last_class()->listRoutes(); + }); + + + RouteCollection::cli('/purge/[h:module]', function($module){ + echo "Purgin $module\n"; + }); + + RouteCollection::cli('/purge', function(){ + echo "Purging Everything\n"; + }); + + RouteCollection::cli('/create/[h:subname]/[h:name]', 'GeneratorController@createPluginFromTemplate'); }); \ No newline at end of file