| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434 |
- <?php
- namespace App\Core\Generator;
- class GeneratorController {
- private $langBase =
- <<<EOL
- <?php
- \$lang["{{PLUGIN_NAME}}"]["module_name"] = "{{PLUGIN_NAME_PRETTY}}";
- EOL;
- private $migrationBase =
- <<<EOL
- <?php
- use Schema\Wrapper as Wrapper;
- use App\Core\Sanity\MigratorController as Migrator;
- //https://book.cakephp.org/phinx/0/en/migrations.html#valid-column-types
- function {{PLUGIN_NAME}}_upgrade(\$pluginversion) {
- if (\$pluginversion < "0.0.1") {
- \$table = Wrapper::get_table("{{PLUGIN_NAME}}s");
- \$table->addColumn("area_id", "integer", Array("null" => false));
- \$table->addColumn("name", "string", Array("null" => false));
- \$table->addColumn("description", "text", Array("null" => true));
- //\$table->addColumn("time", "timestamp", Array("null" => true, "default"=>null));
- \$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}}s");
- // 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}}s");
- \$table->drop();
- return;
- }
- }
- EOL;
- private $versionBase =
- <<<EOL
- <?php
- \$plugin->name = "{{PLUGIN_NAME}}";
- \$plugin->version = "0.0.0";
- //\$plugin->require = Array( ["name" => "plugin_name", "version" => "x.x.x"] );
- EOL;
- private $controllerBase =
- <<<EOL
- <?php
- namespace {{NAMESPACE}};
- use \App\Core\Template\Output as Output;
- use \{{NAMESPACE}}\Classes\{{OBJECT}} as {{OBJECT}};
- class {{CONTROLLER}} extends \DefaultController{
- protected \$_class = {{OBJECT}}::class;
- protected \$_baseUrl = '/{{PLUGIN_NAME}}';
- /**
- * Index
- * Show the main {{OBJECT}} list
- */
- function 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::render('index', Array('list' => \$list));
- }
- /**
- * Create
- *
- * Render the main {{OBJECT}} formulary
- */
- function create(){
- Output::render('form', ['id' => 0]);
- }
- /**
- * Store
- *
- * Store the param on the database
- * @param {{OBJECT}} \${{OBJECT_LOWER}}
- */
- function store({{OBJECT}} \${{OBJECT_LOWER}}){
- }
- /**
- * Search
- *
- * Store the param on the database
- * @param {{OBJECT}} \${{OBJECT_LOWER}}
- */
- function search(){
- }
- /**
- * Show
- *
- * Render one register
- *
- * @param {{OBJECT}} \${{OBJECT_LOWER}}
- */
- function show({{OBJECT}} \${{OBJECT_LOWER}}){
- }
- /**
- * Edit
- *
- * Render the formular for a database {{OBJECT}}
- *
- * @param {{OBJECT}} \${{OBJECT_LOWER}}
- */
- function edit({{OBJECT}} \${{OBJECT_LOWER}}){
- Output::render('form', \${{OBJECT_LOWER}});
- }
- /**
- * Update
- * Store the changes of the param on the database
- *
- * @param {{OBJECT}} \${{OBJECT_LOWER}}
- */
- function update({{OBJECT}} \${{OBJECT_LOWER}}){
- }
- /**
- * Destroy
- * If the object has soft delete.
- *
- * @param {{OBJECT}} \${{OBJECT_LOWER}}
- */
- function destroy({{OBJECT}} \${{OBJECT_LOWER}}){
- }
- /**
- * Purge
- * Remove object even with soft delete.
- *
- * @param {{OBJECT}} \${{OBJECT_LOWER}}
- */
- function purge({{OBJECT}} \${{OBJECT_LOWER}}){
- }
- }
- EOL;
- private $objectBase =
- <<<EOL
- <?php
- 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}}s";
- /*const _properties = Array(
- "id" => ['listable' => true, 'searcheble' => false, 'orderable' => false],
- "name" => ['listable' => true, 'searcheble' => true]);
- */
- const _properties = Array(
- 'id',
- 'name',
- 'description'
- );
- /*protected \$_ignore = Array(
- );*/
- const _listable = Array(
- 'id',
- 'name'
- );
- const _searchable = Array(
- 'name'
- );
- const _orderable = Array(
- );
- /*const _datatables = Array(
- );*/
- //const _timestamps = true;
- //const _softdelete = true;
- //const _connectionName = "";
- }
- EOL;
- private $routeBase =
- <<<EOL
- <?php
- use App\Core\Template\Output as Output;
- use Routes\RouteCollection as RouteCollection;
- //Menu itens
- RouteCollection::get('*', function() {
- Output::addMenu('/{{PLUGIN_NAME}}', '{{PLUGIN_NAME}}', icon('cubes'), ['class' => 'nav-link']);
- }, -10)->doIgnore();
- RouteCollection::group("/{{PLUGIN_NAME}}", function(){
- RouteCollection::get ("/", "\{{NAMESPACE}}\{{CONTROLLER}}@index");
- RouteCollection::get ("/form", "\{{NAMESPACE}}\{{CONTROLLER}}@create");
- RouteCollection::post ("/", "\{{NAMESPACE}}\{{CONTROLLER}}@store");
- RouteCollection::post ("/search", "\{{NAMESPACE}}\{{CONTROLLER}}@search");
- 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>
- EOL;
- private $formTemplate =
- <<<EOL
- {{#id}}
- <form method="POST" action="/{{ENDPOINT}}/{{id}}/edit">
- <input type="hidden" name="id" value="{{id}}" />
- <input type="hidden" name="_method" value="put" />
- {{/id}}
- {{^id}}
- <form method="POST" action="/{{ENDPOINT}}">
- <input type="hidden" name="id" value="" />
- {{/id}}
- <div class='row'>
- <div class="col-md-8 col-xs-12 g-3">
- <div class="card">
- <div class="card-header">Header</div>
- <div class="card-body">
- <div class="row g-3">
- <div class="col-xs-12 col-3">
- <label class="form-label">Código</label>
- <input type="text" class="form-control" name='code' value="{{code}}">
- </div>
- <div class="col-xs-12 col-9">
- <label class="form-label">Nome</label>
- <input type="text" class="form-control" name='name' value="{{name}}">
- </div>
- </div>
- <div class="row">
- <div class="col-xs-12 g-3">
- <label class="form-label">Descrição</label>
- <textarea class="form-control" name="descricao">{{description}}</textarea>
- </div>
- </div>
- </div>
- </div>
- </div>
- <div class="col-md-4 col-xs-12 g-3">
- <div class="card">
- <div class="card-header">Header</div>
- <div class="card-body">
- <div class="row g-3">
- <div class="col-xs-12 col-3">
- <label class="form-label">Código</label>
- <input type="text" class="form-control" name='code' value="{{code}}">
- </div>
- <div class="col-xs-12 col-9">
- <label class="form-label">Nome</label>
- <input type="text" class="form-control" name='name' value="{{name}}">
- </div>
- </div>
- <div class="row">
- <div class="col-xs-12 g-3">
- <label class="form-label">Descrição</label>
- <textarea class="form-control" name="descricao">{{description}}</textarea>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- <div class='row'>
- <div class="col-md-8 col-xs-12 g-3">
- <div class="card">
- <div class="card-header">Header</div>
- <div class="card-body">
- <div class="row g-3">
- <div class="col-xs-12 col-3">
- <label class="form-label">Código</label>
- <input type="text" class="form-control" name='code' value="{{code}}">
- </div>
- <div class="col-xs-12 col-9">
- <label class="form-label">Nome</label>
- <input type="text" class="form-control" name='name' value="{{name}}">
- </div>
- </div>
- <div class="row">
- <div class="col-xs-12 g-3">
- <label class="form-label">Descrição</label>
- <textarea class="form-control" name="descricao">{{description}}</textarea>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </form>
- EOL;
- private $todoList =
- <<<EOL
- EOL;
- function createPluginFromTemplate($subname, $name){
- if (is_dir( DIR_APP.$subname . "/" . $name )){
- echo "This module allready exist";
- 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);
- }
- $plugin_name = $name;
- $namespace = "App\\".ucfirst($subname)."\\".ucfirst($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_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}}", $subname."_".$plugin_name, $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);
- $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("{{NAMESPACE}}", $namespace, $this->controllerBase);
- $this->controllerBase = str_replace("{{PLUGIN_NAME}}", $plugin_name, $this->controllerBase);
- $this->controllerBase = str_replace("{{OBJECT}}", $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);
- $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);
- file_put_contents(DIR_APP.$subname . "/" . $name . "/todo.md", $this->todoList);
- }
- 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";
- 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);
- }else{
- echo str_pad($route->_callback[0], 30, " ", STR_PAD_RIGHT);
- }
- echo "\n";
- }
- }
- }
|