Forráskód Böngészése

Reestruturacao da pasta app e mudancas nos templates

ahwelp 5 éve
szülő
commit
9548157f02

+ 12 - 12
application/module/core/generator/GeneratorController.php → app/core/generator/GeneratorController.php

@@ -125,15 +125,15 @@ class GeneratorController {
             EOL;
     
     function createPluginFromTemplate($subname, $name){
-        if (is_dir( DIR_MODULE.$subname . '/' . $name )){
+        if (is_dir( DIR_APP.$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);            
+            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;
@@ -143,23 +143,23 @@ class GeneratorController {
         
         $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);
+        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_MODULE.$subname . '/' . $name . '/db/Migrate.php', $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_MODULE.$subname . '/' . $name . '/Routes.php', $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_MODULE.$subname . '/' . $name . "/classes/$object.php", $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_MODULE.$subname . '/' . $name . "/$controller.php", $this->controllerBase);
+        file_put_contents(DIR_APP.$subname . '/' . $name . "/$controller.php", $this->controllerBase);
        
         
     }

+ 0 - 0
application/module/core/generator/Routes.php → app/core/generator/Routes.php


+ 0 - 0
application/module/core/lang/en.php → app/core/lang/en.php


+ 0 - 0
application/module/core/lang/pt_br.php → app/core/lang/pt_br.php


+ 0 - 0
application/module/core/sanity/Routes.php → app/core/sanity/Routes.php


+ 2 - 2
application/module/core/sanity/classes/Migrator.class.php → app/core/sanity/classes/Migrator.class.php

@@ -86,7 +86,7 @@ class Migrator{
         $module_configs = Array();
         $plugins = Array();
 
-        $rdi = new RecursiveDirectoryIterator(DIR_MODULE);
+        $rdi = new RecursiveDirectoryIterator(DIR_APP);
 
         foreach(new RecursiveIteratorIterator($rdi) as $file){
             if( strpos($file, 'version.php') ){
@@ -180,4 +180,4 @@ class Migrator{
         $this->save();
     }
 
-}
+}

+ 0 - 0
application/module/core/sanity/lib.php → app/core/sanity/lib.php


+ 28 - 20
application/module/core/template/Output.class.php → app/core/template/Output.class.php

@@ -1,5 +1,7 @@
 <?php
 
+namespace App\Core\Template;
+
 class Output {
 
     private static $_instance;
@@ -10,7 +12,6 @@ class Output {
     private $_template = '';
     private $_extension = '';
     
-    //SINGLETON==============================================
     private function __construct() {
         $this->_template = ( defined('TEMPLATE_DEFAULT') ) ? TEMPLATE_DEFAULT : 'DefaultTemplate';
         $this->_extension = ( defined('TEMPLATE_FILETYPE') ) ? TEMPLATE_FILETYPE : '.mustache';
@@ -31,8 +32,9 @@ class Output {
     }
 
     public function setTemplate($template = 'DefaultTemplate') {
-        $this->_template = $template;
-        return $this;
+        self::getInstance()->_template = $template;
+//        self::getInstance()->_template = '';
+        return self::getInstance();
     }
 
     public static function renderView($name, $values = null, $location = null) {
@@ -42,11 +44,11 @@ class Output {
             $location = implode('/', $segments) . '/views/';
         }
         
-        self::$_instance->setView($name, $values, $location)->render();
+        self::getInstance()->setView($name, $values, $location)->render();
     }
 
-    public function setView($name, $values = Array(), $location = null) {
-        
+    public static function setView($name, $values = Array(), $location = null) {
+        $instance =  self::getInstance();
         $folder = '';
         if (!$location) {
             $segments = explode('/', debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)[0]['file']);
@@ -56,26 +58,32 @@ class Output {
         $folder = $location;
         $location .= $name;
 
-        if (strpos($this->_extension, $location) == 0) {
-            $location .= $this->_extension;
+        if (strpos($instance->_extension, $location) == 0) {
+            $location .= $instance->_extension;
         }
 
-        $this->view = Array();
-        $this->view['location'] = $location;
-        $this->view['folder'] = $folder;
-        $this->view['values'] = $values;
-        return $this;
+        $instance->view = Array();
+        $instance->view['location'] = $location;
+        $instance->view['folder'] = $folder;
+        $instance->view['values'] = $values;
+        return self::getInstance();
     }
 
-    public function addValue($key, $value){
-        $this->view['values'][$key] = $value;
+    public static function addValue($key, $value){
+        self::getInstance()->view['values'][$key] = $value;
     }
 
-    public function render() {
-        if(!is_file(__DIR__."/classes/".strtolower($this->_template)."/".$this->_template.'.php') ){
-            $this->_template = 'DefaultTemplate';
+    public static function render() {
+        $instance = self::getInstance();
+
+        if(!is_file(__DIR__."/classes/".strtolower($instance->_template)."/".$instance->_template.'.php') ){
+            $instance->_template = 'DefaultTemplate';
         }
-        include_once __DIR__."/classes/".strtolower($this->_template)."/".$this->_template.'.php';
-        last_class()->setView($this->view)->render();
+
+        include_once __DIR__."/classes/".strtolower($instance->_template)."/".$instance->_template.'.php';
+        
+        $class = new $instance->_template;
+        $class->setView($instance->view)->render();
+
     }
 }

+ 2 - 4
application/module/core/template/Routes.php → app/core/template/Routes.php

@@ -7,11 +7,9 @@ RouteCollection::get('*', function(){
 
     include_once 'Output.class.php';
 
-    GLOBAL $SIDEBAR, $DROPDOWN, $OUTPUT;
+    GLOBAL $SIDEBAR, $DROPDOWN;
 
     $SIDEBAR = new Menu( array('id' => 'side-menu', 'class' => "nav") );
     $DROPDOWN = new Menu( array("class" => 'dropdown-menu') );
 
-    $OUTPUT = Output::getInstance();
-
-}, -11)->doIgnore();
+}, -11)->doIgnore();

+ 0 - 0
application/module/core/template/classes/dashboard/Dashboard.php → app/core/template/classes/dashboard/Dashboard.php


+ 0 - 0
application/module/core/template/classes/dashboard/template.html → app/core/template/classes/dashboard/template.html


+ 0 - 0
application/module/core/template/classes/defaulttemplate/DefaultTemplate.php → app/core/template/classes/defaulttemplate/DefaultTemplate.php


+ 0 - 0
application/module/core/template/classes/defaulttemplate/template.html → app/core/template/classes/defaulttemplate/template.html


+ 0 - 0
application/module/core/template/classes/nulltemplate/NullTemplate.php → app/core/template/classes/nulltemplate/NullTemplate.php


+ 17 - 0
app/core/wellcome/Routes.php

@@ -0,0 +1,17 @@
+<?php
+
+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::addValue('string', Array('welcome' => 'Bem vindo'));
+    Output::addValue('palavrinha', 'Oi');
+    Output::render();
+});
+
+RouteCollection::add('get', '/welcome', 'WellcomeController@welcome');

+ 0 - 0
application/module/core/wellcome/WellcomeController.php → app/core/wellcome/WellcomeController.php


+ 0 - 0
application/module/core/wellcome/lang/en.php → app/core/wellcome/lang/en.php


+ 0 - 0
application/module/core/wellcome/lang/fr.php → app/core/wellcome/lang/fr.php


+ 0 - 0
application/module/core/wellcome/lang/pt_br.php → app/core/wellcome/lang/pt_br.php


+ 0 - 0
application/module/core/wellcome/views/wellcome.mustache → app/core/wellcome/views/wellcome.mustache


+ 0 - 18
application/module/core/wellcome/Routes.php

@@ -1,18 +0,0 @@
-<?php
-
-use Routes\RouteCollection as RouteCollection;
-
-include_once 'WellcomeController.php';
-
-RouteCollection::add('GET','/', function(){
-
-    global $OUTPUT;
-    $OUTPUT->setTemplate();
-    //$OUTPUT->renderView('wellcome', Array('string' => Array('welcome' => 'Bem vindo')));
-    $OUTPUT->setView('wellcome');
-    $OUTPUT->addValue('string', Array('welcome' => 'Bem vindo'));
-    $OUTPUT->addValue('palavrinha', 'Oi');
-    $OUTPUT->render();
-});
-
-RouteCollection::add('get', '/welcome', 'WellcomeController@welcome');

+ 1 - 1
bootstrap.php

@@ -12,5 +12,5 @@ use Routes\RouteCollection as RouteCollection;
 
 Lang::buildStrings();
 
-RouteCollection::getInstance()->crawl(__DIR__.'/application')->loadRoutes();
+RouteCollection::getInstance()->crawl(DIR_APP)->loadRoutes();
 RouteCollection::getInstance()->submit();

+ 2 - 3
config/info.php

@@ -4,8 +4,7 @@ define('APP_LANG', 'pt_br');
 
 define('DIR_CONFIG', __DIR__.'/');
 define('DIR_ROOT', __DIR__.'/../');
-define('DIR_APPLICATION', DIR_ROOT . 'application/');
-define('DIR_MODULE', DIR_APPLICATION . 'module/');
+define('DIR_APP', DIR_ROOT . 'app/');
 
 define('TEMPLATE_DEFAULT', 'Dashboard');
 //define('TEMPLATE_DEFAULT', 'DefaultTemplate');
@@ -14,4 +13,4 @@ define('TEMPLATE_FILETYPE', '.mustache');
 
 define('INSTALL_REQUIRE', FALSE);
 
-define('CACHE_LANG', FALSE);
+define('CACHE_LANG', FALSE);

+ 21 - 2
publiclib.php

@@ -1,5 +1,24 @@
 <?php
 
+spl_autoload_register(function ($class_name) {
+    $path = explode('\\', $class_name);
+    $fileName = $path[sizeof($path)-1];
+
+    $path[sizeof($path)-1] = '';
+
+    $path = strtolower(implode(DIRECTORY_SEPARATOR, $path));
+
+    if(is_file($path . $fileName . '.php')){
+        return include $path . $fileName . '.php';
+    }
+
+    if(is_file(strtolower($path . $fileName . '.php'))){
+        return include strtolower($path . $fileName . '.php');
+    }
+
+    include $path . $fileName . '.php';
+});
+
 class Connection {
 
     private function __construct() {
@@ -96,7 +115,7 @@ class Lang {
             return;
         }
 
-        $rdi = new RecursiveDirectoryIterator(DIR_APPLICATION);
+        $rdi = new RecursiveDirectoryIterator(DIR_APP);
         foreach (new RecursiveIteratorIterator($rdi) as $file) {
             if (preg_match("/lang\/.*\.php$/", $file)) {
                 $included_lang = explode('/', $file);
@@ -113,4 +132,4 @@ class Lang {
 
 abstract class Controller {
     
-}
+}