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 {
//The folder to be created private $langBase =
private $name_path = ''; <<<EOL
//The tables to be created <?php
private $tables = Array(); \$lang['{{PLUGIN_NAME}}']['module_name'] = '{{PLUGIN_NAME_PRETTY}}';
EOL;
function menu() { private $migrationBase =
<<<EOL
<?php
$default_behavior = function (CliMenu $clm) { use Schema\Wrapper as Wrapper;
}; function {{PLUGIN_NAME}}_upgrade(\$pluginversion) {
if (\$pluginversion < '1.0.0') {
\$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();
$module_name = function(CliMenu $clm) { Migrator::getInstance()->update_plugin_version('{{PLUGIN_NAME}}', '1.0.0');
return;
}
$result = $clm->askText() //if (\$pluginversion < '1.0.1') {
->setPlaceholderText('Enter something here') //\$table = Wrapper::get_table('{{PLUGIN_NAME}}');
->ask(); //Migrator::getInstance()->update_plugin_version('{{PLUGIN_NAME}}', '1.0.1');
//return;
//}
}
EOL;
$this->name_path = $result->fetch(); private $versionBase =
$clm->getSelectedItem()->showItemExtra(); <<<EOL
}; <?php
$show_info = function(CliMenu $clm) { \$plugin->name = '{{PLUGIN_NAME}}';
$clm->flash('Module name and path \n' . $this->name_path)->display(); \$plugin->version = '0.0.1';
};
/* $menu = (new CliMenuBuilder) //\$plugin->require = Array( ["name" => "plugin_name", "version" => 'x.x.x'] );
->setTitle(Lang::getString('main_title', 'generator')) EOL;
->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(); */ private $controllerBase =
/* $menu = (new CliMenuBuilder) <<<EOL
->setTitle('CLI Menu') <?php
->addItem('First Item', $default_behavior) class {{CONTROLLER}} {
->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) function index(){
->addItem('Normal Item', function(){})
->addSubMenu('Super Sub Menu', function (CliMenuBuilder $b) { }
$b->setTitle('Behold the awesomeness')
->addItem('asdasdasdas', function(){}); function create(){
})
->build(); }
$menu->open();
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;
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 =
<<<EOL
<?php
use Routes\RouteCollection as RouteCollection;
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;
} }
} }
+10 -11
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(){ include_once 'GeneratorController.php';
echo "Purging Everything\n";
RouteCollection::cli('/routes', function(){
last_class()->listRoutes();
}); });
RouteCollection::cli('/core/purge/[h:module]', function($module){
RouteCollection::cli('/purge/[h:module]', function($module){
echo "Purgin $module\n"; echo "Purgin $module\n";
}); });
RouteCollection::cli('/core/routes', function(){ RouteCollection::cli('/purge', function(){
foreach(RouteCollection::returnRoutes() as $route){ echo "Purging Everything\n";
echo str_pad( implode(',', $route->_verb), 10) . "| $route->_uri \n";
}
}); });
RouteCollection::cli('/core/generator', function(){ RouteCollection::cli('/create/[h:subname]/[h:name]', 'GeneratorController@createPluginFromTemplate');
include_once 'GeneratorController.php';
last_class()->menu();
}); });