Adicionando mudancas gerador

This commit is contained in:
2020-02-07 12:04:41 -02:00
parent 2e1366f114
commit b66dcff003
2 changed files with 188 additions and 80 deletions
@@ -1,75 +1,184 @@
<?php <?php
use PhpSchool\CliMenu\CliMenu; use Routes\RouteCollection as RouteCollection;
use PhpSchool\CliMenu\Builder\CliMenuBuilder;
class GeneratorController { class GeneratorController {
private $langBase =
<<<EOL
<?php
\$lang['{{PLUGIN_NAME}}']['module_name'] = '{{PLUGIN_NAME_PRETTY}}';
EOL;
private $migrationBase =
<<<EOL
<?php
//The folder to be created use Schema\Wrapper as Wrapper;
private $name_path = '';
//The tables to be created
private $tables = Array();
function menu() { function {{PLUGIN_NAME}}_upgrade(\$pluginversion) {
if (\$pluginversion < '1.0.0') {
$default_behavior = function (CliMenu $clm) { \$table = Wrapper::get_table('{{PLUGIN_NAME}}');
\$table->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 =
<<<EOL
<?php
$module_name = function(CliMenu $clm) { \$plugin->name = '{{PLUGIN_NAME}}';
\$plugin->version = '0.0.1';
//\$plugin->require = Array( ["name" => "plugin_name", "version" => 'x.x.x'] );
EOL;
private $controllerBase =
<<<EOL
<?php
class {{CONTROLLER}} {
function index(){
}
function create(){
}
function Store(){
}
function show({{OBJECT}} \$instance){
}
function edit({{OBJECT}} \$instance){
}
function update({{OBJECT}} \$instance){
}
function destroy({{OBJECT}} \$instance){
}
function purge({{OBJECT}} \$instance){
}
}
EOL;
private $objectBase =
<<<EOL
<?php
use ORM\Entity as Entity;
$result = $clm->askText() class {{OBJECT}} extends Entity {
->setPlaceholderText('Enter something here')
->ask(); //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 =
<<<EOL
<?php
$this->name_path = $result->fetch(); use Routes\RouteCollection as RouteCollection;
$clm->getSelectedItem()->showItemExtra();
};
$show_info = function(CliMenu $clm) { RouteCollection::group('/{{PLUGIN_NAME}}', function(){
$clm->flash('Module name and path \n' . $this->name_path)->display(); RouteCollection::get ('/', '{{CONTROLLER}}@index');
}; RouteCollection::get ('/', '{{CONTROLLER}}@create');
RouteCollection::post ('/', '{{CONTROLLER}}@store');
/* $menu = (new CliMenuBuilder) RouteCollection::get ('/[i:id]', '{{CONTROLLER}}@show');
->setTitle(Lang::getString('main_title', 'generator')) RouteCollection::get ('/[i:id]/edit', '{{CONTROLLER}}@edit');
->addItem(Lang::getString('name_definition', 'generator'), $module_name) RouteCollection::put ('/[i:id]/edit', '{{CONTROLLER}}@update');
->addItem(Lang::getString('show_info', 'generator'), $show_info) RouteCollection::delete('/[i:id]', '{{CONTROLLER}}@destroy');
->setItemExtra('[COMPLETE!]') });
->addLineBreak('-') EOL;
->setBorder(1, 2, 'yellow')
->setPadding(2, 4) function createPluginFromTemplate($subname, $name){
//->setMarginAuto() if (is_dir( DIR_MODULE.$subname . '/' . $name )){
->build(); echo 'Treco ja existe';
return;
$menu->open(); */ }else{
/* $menu = (new CliMenuBuilder) mkdir(DIR_MODULE.$subname . '/' . $name, 0755, true);
->setTitle('CLI Menu') mkdir(DIR_MODULE.$subname . '/' . $name . '/lang', 0755, true);
->addItem('First Item', $default_behavior) mkdir(DIR_MODULE.$subname . '/' . $name . '/classes', 0755, true);
->addItem('Second Item', $default_behavior) mkdir(DIR_MODULE.$subname . '/' . $name . '/db', 0755, true);
->addLineBreak('-') mkdir(DIR_MODULE.$subname . '/' . $name . '/views', 0755, true);
->addSubMenu('Options', function (CliMenuBuilder $b) { }
$b->setTitle('CLI Menu > Options')
->addItem('First option', function (CliMenu $menu) { $plugin_name = $name;
echo sprintf('Executing option: %s', $menu->getSelectedItem()->getText()); $plugin_name_pretty = ucwords(str_replace('_', ' ', $name));
}) $object = ucfirst( $name );
->addLineBreak('-'); $controller = $object.'Controller';
})
->setWidth(70) $this->langBase = str_replace("{{PLUGIN_NAME}}", $plugin_name, $this->langBase);
->setBackgroundColour('yellow') $this->langBase = str_replace("{{PLUGIN_NAME_PRETTY}}", $plugin_name_pretty, $this->langBase);
->build(); file_put_contents(DIR_MODULE.$subname . '/' . $name . '/lang/en.php', $this->langBase);
$menu->open(); */ file_put_contents(DIR_MODULE.$subname . '/' . $name . '/lang/'.APP_LANG.'.php', $this->langBase);
$callable = function (CliMenu $menu) {
echo "I'm just a boring selectable item"; $this->migrationBase = str_replace("{{PLUGIN_NAME}}", $plugin_name, $this->migrationBase);
}; file_put_contents(DIR_MODULE.$subname . '/' . $name . '/db/Migrate.php', $this->migrationBase);
$menu = (new CliMenuBuilder) $this->routeBase = str_replace("{{PLUGIN_NAME}}", $plugin_name, $this->routeBase);
->addItem('Normal Item', function(){}) $this->routeBase = str_replace("{{CONTROLLER}}", $controller, $this->routeBase);
->addSubMenu('Super Sub Menu', function (CliMenuBuilder $b) { file_put_contents(DIR_MODULE.$subname . '/' . $name . '/Routes.php', $this->routeBase);
$b->setTitle('Behold the awesomeness')
->addItem('asdasdasdas', function(){}); $this->objectBase = str_replace("{{OBJECT}}", $object, $this->objectBase);
}) $this->objectBase = str_replace("{{TABLE_NAME}}", $name, $this->objectBase);
->build(); file_put_contents(DIR_MODULE.$subname . '/' . $name . "/classes/$object.php", $this->objectBase);
$menu->open();
$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;
}
} }
+17 -18
View File
@@ -2,24 +2,23 @@
use Routes\RouteCollection as RouteCollection; use Routes\RouteCollection as RouteCollection;
RouteCollection::group('/core', function(){
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(){
include_once 'GeneratorController.php'; 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');
}); });