More changes

This commit is contained in:
ahwelp
2020-07-22 03:34:33 -03:00
parent 5840d1338b
commit df312bdc1b
11 changed files with 461 additions and 286 deletions
+189 -70
View File
@@ -7,7 +7,7 @@ class GeneratorController {
private $langBase =
<<<EOL
<?php
\$lang['{{PLUGIN_NAME}}']['module_name'] = '{{PLUGIN_NAME_PRETTY}}';
\$lang["{{PLUGIN_NAME}}"]["module_name"] = "{{PLUGIN_NAME_PRETTY}}";
EOL;
private $migrationBase =
@@ -17,35 +17,43 @@ class GeneratorController {
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));
if (\$pluginversion < "0.0.1") {
\$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');
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');
//if (\$pluginversion < "0.0.2") {
//\$table = Wrapper::get_table("{{PLUGIN_NAME}}");
//Migrator::getInstance()->update_plugin_version("{{PLUGIN_NAME}}", "1.0.1");
//return;
//}
}
function {{PLUGIN_NAME}}_rollback(\$pluginversion) {
if(\$pluginversion > "0.0.1"){
\$table = Wrapper::get_table("{{PLUGIN_NAME}}");
\$table->drop();
return;
}
}
EOL;
private $versionBase =
<<<EOL
<?php
\$plugin->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 =
@@ -55,38 +63,93 @@ class GeneratorController {
namespace {{NAMESPACE}};
use \{{NAMESPACE}}\Classes\{{OBJECT}} as {{OBJECT}};
use \App\Core\Template\Output as Output;
class {{CONTROLLER}} {
/**
* Index
* Show the main {{OBJECT}} list
*/
function index(){
Output::setView('index');
\$list = Array();
for(\$i = 0; \$i <= 10; \$i++){
\$obj = Array();
\$obj['id'] = \$i;
\$obj['value'] = md5(\$i);
\$obj['description'] = sha1(\$i);
\$list[] = \$obj;
}
Output::addValue('list', \$list );
Output::render();
}
/**
* Create
* Render the main {{OBJECT}} formular
*/
function create(){
Output::setView('form', ['id' => 0]);
Output::render();
}
function Store(){
/**
* Store
* Store the param on the database
* @param {{OBJECT}} \${{OBJECT_LOWER}}
*/
function store({{OBJECT}} \${{OBJECT_LOWER}}){
}
function show({{OBJECT}} \{{OBJECT_LOWER}}){
/**
* Show
* Render one register
*
* @param {{OBJECT}} \${{OBJECT_LOWER}}
*/
function show({{OBJECT}} \${{OBJECT_LOWER}}){
}
function edit({{OBJECT}} \{{OBJECT_LOWER}}){
/**
* Edit
* Render the formular for a database {{OBJECT}}
*
* @param {{OBJECT}} \${{OBJECT_LOWER}}
*/
function edit({{OBJECT}} \${{OBJECT_LOWER}}){
}
function update({{OBJECT}} \{{OBJECT_LOWER}}){
/**
* Update
* Store the changes of the param on the database
*
* @param {{OBJECT}} \${{OBJECT_LOWER}}
*/
function update({{OBJECT}} \${{OBJECT_LOWER}}){
}
function destroy({{OBJECT}} \{{OBJECT_LOWER}}){
/**
* Destroy
* If the object has soft delete.
*
* @param {{OBJECT}} \${{OBJECT_LOWER}}
*/
function destroy({{OBJECT}} \${{OBJECT_LOWER}}){
}
function purge({{OBJECT}} \{{OBJECT_LOWER}}){
/**
* Purge
* Remove object even with soft delete.
*
* @param {{OBJECT}} \${{OBJECT_LOWER}}
*/
function purge({{OBJECT}} \${{OBJECT_LOWER}}){
}
}
@@ -103,15 +166,15 @@ class GeneratorController {
class {{OBJECT}} extends Entity {
//const _idPolice = Array('type' => '', 'min' => 0, 'max' => 100000, 'step' => 2);
//const _idPolice = Array("type" => "", "min" => 0, "max" => 100000, "step" => 2);
const _tableName = '{{TABLE_NAME}}';
//const _properties = Array('id', 'name');
const _tableName = "{{TABLE_NAME}}";
//const _properties = Array("id", "name");
//const _timestamps = true;
//const _softdelete = true;
//const _connectionName = '';
//const _connectionName = "";
}
EOL;
@@ -121,17 +184,64 @@ class GeneratorController {
use Routes\RouteCollection as RouteCollection;
RouteCollection::group('/{{PLUGIN_NAME}}', function(){
RouteCollection::get ('/', '\{{NAMESPACE}}\{{CONTROLLER}}@index');
RouteCollection::get ('/', '\{{NAMESPACE}}\{{CONTROLLER}}@create');
RouteCollection::post ('/', '\{{NAMESPACE}}\{{CONTROLLER}}@store');
RouteCollection::get ('/[i:id]', '\{{NAMESPACE}}\{{CONTROLLER}}@show');
RouteCollection::get ('/[i:id]/edit', '\{{NAMESPACE}}\{{CONTROLLER}}@edit');
RouteCollection::put ('/[i:id]/edit', '\{{NAMESPACE}}\{{CONTROLLER}}@update');
RouteCollection::delete('/[i:id]', '\{{NAMESPACE}}\{{CONTROLLER}}@destroy');
RouteCollection::group("/{{PLUGIN_NAME}}", function(){
RouteCollection::get ("/", "\{{NAMESPACE}}\{{CONTROLLER}}@index");
RouteCollection::get ("/form", "\{{NAMESPACE}}\{{CONTROLLER}}@create");
RouteCollection::post ("/", "\{{NAMESPACE}}\{{CONTROLLER}}@store");
RouteCollection::get ("/[i:id]", "\{{NAMESPACE}}\{{CONTROLLER}}@show");
RouteCollection::get ("/[i:id]/edit", "\{{NAMESPACE}}\{{CONTROLLER}}@edit");
RouteCollection::put ("/[i:id]/edit", "\{{NAMESPACE}}\{{CONTROLLER}}@update");
RouteCollection::delete("/[i:id]", "\{{NAMESPACE}}\{{CONTROLLER}}@destroy");
});
EOL;
private $indexTemplate =
<<<EOL
<a href='{{ENDPOINT}}/form' >Adicionar </a>
<div class="table-responsive">
<table class='table'>
<thead>
<tr>
<th>Id</th>
<th>Value</th>
<th>Description</th>
<th>Actions</th>
</tr>
</thead>
{{#list}}
<tr class="table-dark" data-id='{{id}}'>
<td>{{id}}</td>
<td>{{value}}</td>
<td>{{description}}</td>
<td>
<a href="{{ENDPOINT}}/edit"> <i class="fa fa-pencil"></i></a>
<a href="{{ENDPOINT}}/purge"> <i class="fa fa-fire"></i></a>
<a href="{{ENDPOINT}}/"> <i class="fa fa-plus"></i></a>
<a href="{{ENDPOINT}}/destroy"> <i class="fa fa-trash-o"></i></a>
</td>
</tr>
{{/list}}
</table>
</div>
EOL;
private $formTemplate =
<<<EOL
{{@ if( {{id}} ): @}}
<form method="POST" action="{{ENDPOINT}}/{{id}}/edit">
<input type="hidden" name="id" value="{{id}}" />
<input type="hidden" name="_method" value="put" />
{{@ else: @}}
<form method="POST" action="{{ENDPOINT}}">
<input type="hidden" name="id" value="" />
{{@ endif; @}}
</form>
EOL;
private $ctagsHeader =
<<<EOL
!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
@@ -146,63 +256,72 @@ class GeneratorController {
function createPluginFromTemplate($subname, $name){
if (is_dir( DIR_APP.$subname . '/' . $name )){
echo 'Treco ja existe';
if (is_dir( DIR_APP.$subname . "/" . $name )){
echo "Treco ja existe";
return;
}else{
mkdir(DIR_APP.$subname . '/' . $name, 0755, true);
mkdir(DIR_APP.$subname . '/' . $name . '/lang', 0755, true);
mkdir(DIR_APP.$subname . '/' . $name . '/classes', 0755, true);
mkdir(DIR_APP.$subname . '/' . $name . '/db', 0755, true);
mkdir(DIR_APP.$subname . '/' . $name . '/views', 0755, true);
mkdir(DIR_APP.$subname . "/" . $name, 0755, true);
mkdir(DIR_APP.$subname . "/" . $name . "/lang", 0755, true);
mkdir(DIR_APP.$subname . "/" . $name . "/classes", 0755, true);
mkdir(DIR_APP.$subname . "/" . $name . "/db", 0755, true);
mkdir(DIR_APP.$subname . "/" . $name . "/views", 0755, true);
}
$plugin_name = $name;
$namespace = "App\\".ucfirst($subname).'\\'.ucfirst($name);
$plugin_name_pretty = ucwords(str_replace('_', ' ', $name));
$namespace = "App\\".ucfirst($subname)."\\".ucfirst($name);
$plugin_name_pretty = ucwords(str_replace("_", " ", $name));
$object = ucfirst( $name );
$controller = $object.'Controller';
$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_APP.$subname . '/' . $name . '/lang/en.php', $this->langBase);
file_put_contents(DIR_APP.$subname . '/' . $name . '/lang/'.APP_LANG.'.php', $this->langBase);
file_put_contents(DIR_APP.$subname . "/" . $name . "/lang/en.php", $this->langBase);
file_put_contents(DIR_APP.$subname . "/" . $name . "/lang/".APP_LANG.".php", $this->langBase);
$this->migrationBase = str_replace("{{PLUGIN_NAME}}", $plugin_name, $this->migrationBase);
file_put_contents(DIR_APP.$subname . '/' . $name . '/db/Migrate.php', $this->migrationBase);
file_put_contents(DIR_APP.$subname . "/" . $name . "/db/Migrate.php", $this->migrationBase);
$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);
file_put_contents(DIR_APP.$subname . "/" . $name . "/Routes.php", $this->routeBase);
$this->objectBase = str_replace("{{NAMESPACE}}", $namespace.'\Classes', $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);
file_put_contents(DIR_APP.$subname . "/" . $name . "/classes/$object.php", $this->objectBase);
$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("{{OBJECT_LOWER}}",strtolower($object), $this->controllerBase);
$this->controllerBase = str_replace("{{CONTROLLER}}", $controller, $this->controllerBase);
file_put_contents(DIR_APP.$subname . '/' . $name . "/$controller.php", $this->controllerBase);
file_put_contents(DIR_APP.$subname . "/" . $name . "/$controller.php", $this->controllerBase);
$this->versionBase = str_replace("{{PLUGIN_NAME}}", $subname."_".$plugin_name, $this->versionBase);
file_put_contents(DIR_APP.$subname . "/" . $name . "/version.php", $this->versionBase);
$this->indexTemplate = str_replace("{{ENDPOINT}}", $plugin_name, $this->indexTemplate);
file_put_contents(DIR_APP.$subname . "/" . $name . "/views/index.mustache", $this->indexTemplate);
$this->formTemplate = str_replace("{{ENDPOINT}}", $plugin_name, $this->formTemplate);
file_put_contents(DIR_APP.$subname . "/" . $name . "/views/form.mustache", $this->formTemplate);
}
function listRoutes(){
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";
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 str_pad('Clousure', 60, ' ', STR_PAD_RIGHT);
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 str_pad("Clousure", 60, " ", STR_PAD_RIGHT);
}else{
echo str_pad($route->_callback[0], 30, ' ', STR_PAD_RIGHT);
echo str_pad($route->_callback[0], 30, " ", STR_PAD_RIGHT);
}
echo "\n";
}
@@ -210,19 +329,19 @@ class GeneratorController {
function createTags(){
$outputs = shell_exec("grep -Rnsi '@ctag' . | sed s/\ //g | sed s/*@ctag/\ /g");
$outputs = preg_split('/\R/', $outputs);
$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') ){
$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);
file_put_contents(DIR_ROOT."tags", $return);
}
}