| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- <?php
- use Routes\RouteCollection as RouteCollection;
- class GeneratorController {
-
- private $langBase =
- <<<EOL
- <?php
- \$lang['{{PLUGIN_NAME}}']['module_name'] = '{{PLUGIN_NAME_PRETTY}}';
- EOL;
-
- private $migrationBase =
- <<<EOL
- <?php
- 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();
-
- 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
- \$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;
- 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_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);
- }
-
- $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_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);
-
- $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->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);
-
-
- }
-
- 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;
- }
-
- }
|