From 5840d1338bcfe43787b4800dbdb2b9192c5ad1f9 Mon Sep 17 00:00:00 2001 From: ahwelp Date: Thu, 16 Apr 2020 22:13:47 -0300 Subject: [PATCH] More changes --- .gitignore | 1 + app/core/generator/GeneratorController.php | 197 +++++++++++------- app/core/generator/Routes.php | 19 +- app/core/{wellcome => welcome}/Routes.php | 7 +- app/core/welcome/WelcomeController.php | 13 ++ app/core/{wellcome => welcome}/lang/en.php | 0 app/core/{wellcome => welcome}/lang/fr.php | 0 app/core/{wellcome => welcome}/lang/pt_br.php | 0 .../views/welcome.mustache} | 0 app/core/wellcome/WellcomeController.php | 11 - publiclib.php | 2 +- 11 files changed, 148 insertions(+), 102 deletions(-) rename app/core/{wellcome => welcome}/Routes.php (68%) create mode 100755 app/core/welcome/WelcomeController.php rename app/core/{wellcome => welcome}/lang/en.php (100%) rename app/core/{wellcome => welcome}/lang/fr.php (100%) rename app/core/{wellcome => welcome}/lang/pt_br.php (100%) rename app/core/{wellcome/views/wellcome.mustache => welcome/views/welcome.mustache} (100%) delete mode 100755 app/core/wellcome/WellcomeController.php diff --git a/.gitignore b/.gitignore index 71f6ae9..5eab223 100755 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .idea nbproject/ +tags config/database.db config/modules.ini diff --git a/app/core/generator/GeneratorController.php b/app/core/generator/GeneratorController.php index 1b6c64a..d1f1673 100755 --- a/app/core/generator/GeneratorController.php +++ b/app/core/generator/GeneratorController.php @@ -1,6 +1,6 @@ name = '{{PLUGIN_NAME}}'; - \$plugin->version = '0.0.1'; + \$plugin->name = '{{PLUGIN_NAME}}'; + \$plugin->version = '0.0.1'; - //\$plugin->require = Array( ["name" => "plugin_name", "version" => 'x.x.x'] ); + //\$plugin->require = Array( ["name" => "plugin_name", "version" => 'x.x.x'] ); EOL; private $controllerBase = << '', 'min' => 0, 'max' => 100000, 'step' => 2); - - const _tableName = '{{TABLE_NAME}}'; - //const _properties = Array('id', 'name'); + namespace {{NAMESPACE}}; + + 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 _timestamps = true; + //const _softdelete = true; - //const _connectionName = ''; - } + //const _connectionName = ''; + } EOL; private $routeBase = <<langBase); file_put_contents(DIR_APP.$subname . '/' . $name . '/lang/'.APP_LANG.'.php', $this->langBase); - $this->migrationBase = str_replace("{{PLUGIN_NAME}}", $plugin_name, $this->migrationBase); + $this->migrationBase = str_replace("{{PLUGIN_NAME}}", $plugin_name, $this->migrationBase); file_put_contents(DIR_APP.$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); + $this->routeBase = str_replace("{{NAMESPACE}}", $namespace, $this->routeBase); + $this->routeBase = str_replace("{{PLUGIN_NAME}}", $plugin_name, $this->routeBase); + $this->routeBase = str_replace("{{CONTROLLER}}", $controller, $this->routeBase); file_put_contents(DIR_APP.$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_APP.$subname . '/' . $name . "/classes/$object.php", $this->objectBase); + $this->objectBase = str_replace("{{NAMESPACE}}", $namespace.'\Classes', $this->objectBase); + $this->objectBase = str_replace("{{OBJECT}}", $object, $this->objectBase); + $this->objectBase = str_replace("{{TABLE_NAME}}", $name, $this->objectBase); + file_put_contents(DIR_APP.$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_APP.$subname . '/' . $name . "/$controller.php", $this->controllerBase); - + $this->controllerBase = str_replace("{{NAMESPACE}}", $namespace, $this->controllerBase); + $this->controllerBase = str_replace("{{OBJECT}}", $object, $this->controllerBase); + $this->controllerBase = str_replace("{{OBJECT_LOWER}}",strlower($object), $this->controllerBase); + $this->controllerBase = str_replace("{{CONTROLLER}}", $controller, $this->controllerBase); + file_put_contents(DIR_APP.$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||"; + echo str_pad('VERB', 10, ' ', STR_PAD_BOTH) . "||"; + echo str_pad('URI' , 35, ' ', STR_PAD_BOTH) . "||"; + echo str_pad('W', 5, ' ', STR_PAD_BOTH) . "||"; + echo str_pad('FUNCTION', 60, ' ', STR_PAD_BOTH) . "\n"; + echo str_pad('', 120, '-') . "\n"; + foreach(\Routes\RouteCollection::returnRoutes() as $route){ + echo str_pad(implode($route->_verb , ', '), 10, ' ', STR_PAD_BOTH) . "||"; + echo str_pad($route->_uri, 35, ' ', STR_PAD_RIGHT) . "||"; + echo str_pad($route->_weight, 5, ' ', STR_PAD_BOTH). "||"; if( gettype($route->_callback[0]) == 'object' ){ - echo 'Clousure ||'; + echo str_pad('Clousure', 60, ' ', STR_PAD_RIGHT); }else{ - echo $route->_callback[0]; + echo str_pad($route->_callback[0], 30, ' ', STR_PAD_RIGHT); } echo "\n"; } - //file_put_contents('/tmp/Route.php', $this->routeBase); - //echo $this->objectBase; - echo APP_LANG; } + + function createTags(){ + $outputs = shell_exec("grep -Rnsi '@ctag' . | sed s/\ //g | sed s/*@ctag/\ /g"); + $outputs = preg_split('/\R/', $outputs); + $return = $this->ctagsHeader . "\n"; + foreach($outputs as $output){ + $line = explode(' ', str_replace('\\t', '', $output) ); + @$line = $line[1] . "\t " . str_replace('./', '', explode(':', $line[0])[0]) . "\t ".$line[1] . "\n"; + if( strpos($line, 'app/core/generator/GeneratorController.php') ){ + continue; + } + $return .= $line; + //echo "Generating: ".$line."\n"; + } + + file_put_contents(DIR_ROOT.'tags', $return); + } } diff --git a/app/core/generator/Routes.php b/app/core/generator/Routes.php index 60b7027..543e93c 100755 --- a/app/core/generator/Routes.php +++ b/app/core/generator/Routes.php @@ -2,14 +2,15 @@ use Routes\RouteCollection as RouteCollection; -RouteCollection::group('/core', function(){ - - include_once 'GeneratorController.php'; - - RouteCollection::cli('/routes', function(){ - last_class()->listRoutes(); - }); +RouteCollection::cli('/', function(){ + echo "/core/create/[h:subname]/[h:name]\n"; +}); +RouteCollection::cli('/routes', '\App\Core\Generator\GeneratorController@listRoutes'); +RouteCollection::cli('/create/tags', '\App\Core\Generator\GeneratorController@createTags'); +RouteCollection::cli('/create/[h:subname]/[h:name]', '\App\Core\Generator\GeneratorController@createPluginFromTemplate'); + +RouteCollection::group('/core', function(){ RouteCollection::cli('/purge/[h:module]', function($module){ echo "Purgin $module\n"; @@ -19,6 +20,4 @@ RouteCollection::group('/core', function(){ echo "Purging Everything\n"; }); - RouteCollection::cli('/create/[h:subname]/[h:name]', 'GeneratorController@createPluginFromTemplate'); - -}); \ No newline at end of file +}); diff --git a/app/core/wellcome/Routes.php b/app/core/welcome/Routes.php similarity index 68% rename from app/core/wellcome/Routes.php rename to app/core/welcome/Routes.php index 5640b11..4146bb6 100755 --- a/app/core/wellcome/Routes.php +++ b/app/core/welcome/Routes.php @@ -3,15 +3,14 @@ use Routes\RouteCollection as RouteCollection; use App\Core\Template\Output as Output; -include_once 'WellcomeController.php'; - RouteCollection::add('GET','/', function(){ Output::setTemplate(''); - Output::setView('wellcome'); + Output::setView('welcome'); Output::addValue('string', Array('welcome' => 'Bem vindo')); Output::addValue('palavrinha', 'Oi'); Output::render(); }); -RouteCollection::add('get', '/welcome', 'WellcomeController@welcome'); +RouteCollection::get('/welcome', '\App\Core\Welcome\WelcomeController@welcome'); + diff --git a/app/core/welcome/WelcomeController.php b/app/core/welcome/WelcomeController.php new file mode 100755 index 0000000..b097354 --- /dev/null +++ b/app/core/welcome/WelcomeController.php @@ -0,0 +1,13 @@ + \Lang::getString('welcome', 'welcome')))->send()->done(); + } + +} diff --git a/app/core/wellcome/lang/en.php b/app/core/welcome/lang/en.php similarity index 100% rename from app/core/wellcome/lang/en.php rename to app/core/welcome/lang/en.php diff --git a/app/core/wellcome/lang/fr.php b/app/core/welcome/lang/fr.php similarity index 100% rename from app/core/wellcome/lang/fr.php rename to app/core/welcome/lang/fr.php diff --git a/app/core/wellcome/lang/pt_br.php b/app/core/welcome/lang/pt_br.php similarity index 100% rename from app/core/wellcome/lang/pt_br.php rename to app/core/welcome/lang/pt_br.php diff --git a/app/core/wellcome/views/wellcome.mustache b/app/core/welcome/views/welcome.mustache similarity index 100% rename from app/core/wellcome/views/wellcome.mustache rename to app/core/welcome/views/welcome.mustache diff --git a/app/core/wellcome/WellcomeController.php b/app/core/wellcome/WellcomeController.php deleted file mode 100755 index 13ea3f2..0000000 --- a/app/core/wellcome/WellcomeController.php +++ /dev/null @@ -1,11 +0,0 @@ - Lang::getString('welcome', 'welcome')))->send()->done(); - } - -} \ No newline at end of file diff --git a/publiclib.php b/publiclib.php index 6f2c3ea..cf7f8a4 100755 --- a/publiclib.php +++ b/publiclib.php @@ -6,7 +6,7 @@ spl_autoload_register(function ($class_name) { $path[sizeof($path)-1] = ''; - $path = strtolower(implode(DIRECTORY_SEPARATOR, $path)); + $path = strtolower(DIR_ROOT. implode(DIRECTORY_SEPARATOR, $path)); if(is_file($path . $fileName . '.php')){ return include $path . $fileName . '.php';