Reestruturacao da pasta app e mudancas nos templates
This commit is contained in:
+12
-12
@@ -125,15 +125,15 @@ class GeneratorController {
|
|||||||
EOL;
|
EOL;
|
||||||
|
|
||||||
function createPluginFromTemplate($subname, $name){
|
function createPluginFromTemplate($subname, $name){
|
||||||
if (is_dir( DIR_MODULE.$subname . '/' . $name )){
|
if (is_dir( DIR_APP.$subname . '/' . $name )){
|
||||||
echo 'Treco ja existe';
|
echo 'Treco ja existe';
|
||||||
return;
|
return;
|
||||||
}else{
|
}else{
|
||||||
mkdir(DIR_MODULE.$subname . '/' . $name, 0755, true);
|
mkdir(DIR_APP.$subname . '/' . $name, 0755, true);
|
||||||
mkdir(DIR_MODULE.$subname . '/' . $name . '/lang', 0755, true);
|
mkdir(DIR_APP.$subname . '/' . $name . '/lang', 0755, true);
|
||||||
mkdir(DIR_MODULE.$subname . '/' . $name . '/classes', 0755, true);
|
mkdir(DIR_APP.$subname . '/' . $name . '/classes', 0755, true);
|
||||||
mkdir(DIR_MODULE.$subname . '/' . $name . '/db', 0755, true);
|
mkdir(DIR_APP.$subname . '/' . $name . '/db', 0755, true);
|
||||||
mkdir(DIR_MODULE.$subname . '/' . $name . '/views', 0755, true);
|
mkdir(DIR_APP.$subname . '/' . $name . '/views', 0755, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$plugin_name = $name;
|
$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}}", $plugin_name, $this->langBase);
|
||||||
$this->langBase = str_replace("{{PLUGIN_NAME_PRETTY}}", $plugin_name_pretty, $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_APP.$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/'.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_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("{{PLUGIN_NAME}}", $plugin_name, $this->routeBase);
|
||||||
$this->routeBase = str_replace("{{CONTROLLER}}", $controller, $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("{{OBJECT}}", $object, $this->objectBase);
|
||||||
$this->objectBase = str_replace("{{TABLE_NAME}}", $name, $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("{{OBJECT}}", $object, $this->controllerBase);
|
||||||
$this->controllerBase = str_replace("{{CONTROLLER}}", $controller, $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);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
+2
-2
@@ -86,7 +86,7 @@ class Migrator{
|
|||||||
$module_configs = Array();
|
$module_configs = Array();
|
||||||
$plugins = Array();
|
$plugins = Array();
|
||||||
|
|
||||||
$rdi = new RecursiveDirectoryIterator(DIR_MODULE);
|
$rdi = new RecursiveDirectoryIterator(DIR_APP);
|
||||||
|
|
||||||
foreach(new RecursiveIteratorIterator($rdi) as $file){
|
foreach(new RecursiveIteratorIterator($rdi) as $file){
|
||||||
if( strpos($file, 'version.php') ){
|
if( strpos($file, 'version.php') ){
|
||||||
@@ -180,4 +180,4 @@ class Migrator{
|
|||||||
$this->save();
|
$this->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+28
-20
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace App\Core\Template;
|
||||||
|
|
||||||
class Output {
|
class Output {
|
||||||
|
|
||||||
private static $_instance;
|
private static $_instance;
|
||||||
@@ -10,7 +12,6 @@ class Output {
|
|||||||
private $_template = '';
|
private $_template = '';
|
||||||
private $_extension = '';
|
private $_extension = '';
|
||||||
|
|
||||||
//SINGLETON==============================================
|
|
||||||
private function __construct() {
|
private function __construct() {
|
||||||
$this->_template = ( defined('TEMPLATE_DEFAULT') ) ? TEMPLATE_DEFAULT : 'DefaultTemplate';
|
$this->_template = ( defined('TEMPLATE_DEFAULT') ) ? TEMPLATE_DEFAULT : 'DefaultTemplate';
|
||||||
$this->_extension = ( defined('TEMPLATE_FILETYPE') ) ? TEMPLATE_FILETYPE : '.mustache';
|
$this->_extension = ( defined('TEMPLATE_FILETYPE') ) ? TEMPLATE_FILETYPE : '.mustache';
|
||||||
@@ -31,8 +32,9 @@ class Output {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function setTemplate($template = 'DefaultTemplate') {
|
public function setTemplate($template = 'DefaultTemplate') {
|
||||||
$this->_template = $template;
|
self::getInstance()->_template = $template;
|
||||||
return $this;
|
// self::getInstance()->_template = '';
|
||||||
|
return self::getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function renderView($name, $values = null, $location = null) {
|
public static function renderView($name, $values = null, $location = null) {
|
||||||
@@ -42,11 +44,11 @@ class Output {
|
|||||||
$location = implode('/', $segments) . '/views/';
|
$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 = '';
|
$folder = '';
|
||||||
if (!$location) {
|
if (!$location) {
|
||||||
$segments = explode('/', debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)[0]['file']);
|
$segments = explode('/', debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)[0]['file']);
|
||||||
@@ -56,26 +58,32 @@ class Output {
|
|||||||
$folder = $location;
|
$folder = $location;
|
||||||
$location .= $name;
|
$location .= $name;
|
||||||
|
|
||||||
if (strpos($this->_extension, $location) == 0) {
|
if (strpos($instance->_extension, $location) == 0) {
|
||||||
$location .= $this->_extension;
|
$location .= $instance->_extension;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->view = Array();
|
$instance->view = Array();
|
||||||
$this->view['location'] = $location;
|
$instance->view['location'] = $location;
|
||||||
$this->view['folder'] = $folder;
|
$instance->view['folder'] = $folder;
|
||||||
$this->view['values'] = $values;
|
$instance->view['values'] = $values;
|
||||||
return $this;
|
return self::getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addValue($key, $value){
|
public static function addValue($key, $value){
|
||||||
$this->view['values'][$key] = $value;
|
self::getInstance()->view['values'][$key] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function render() {
|
public static function render() {
|
||||||
if(!is_file(__DIR__."/classes/".strtolower($this->_template)."/".$this->_template.'.php') ){
|
$instance = self::getInstance();
|
||||||
$this->_template = 'DefaultTemplate';
|
|
||||||
|
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();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,11 +7,9 @@ RouteCollection::get('*', function(){
|
|||||||
|
|
||||||
include_once 'Output.class.php';
|
include_once 'Output.class.php';
|
||||||
|
|
||||||
GLOBAL $SIDEBAR, $DROPDOWN, $OUTPUT;
|
GLOBAL $SIDEBAR, $DROPDOWN;
|
||||||
|
|
||||||
$SIDEBAR = new Menu( array('id' => 'side-menu', 'class' => "nav") );
|
$SIDEBAR = new Menu( array('id' => 'side-menu', 'class' => "nav") );
|
||||||
$DROPDOWN = new Menu( array("class" => 'dropdown-menu') );
|
$DROPDOWN = new Menu( array("class" => 'dropdown-menu') );
|
||||||
|
|
||||||
$OUTPUT = Output::getInstance();
|
}, -11)->doIgnore();
|
||||||
|
|
||||||
}, -11)->doIgnore();
|
|
||||||
Executable
+17
@@ -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');
|
||||||
@@ -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
@@ -12,5 +12,5 @@ use Routes\RouteCollection as RouteCollection;
|
|||||||
|
|
||||||
Lang::buildStrings();
|
Lang::buildStrings();
|
||||||
|
|
||||||
RouteCollection::getInstance()->crawl(__DIR__.'/application')->loadRoutes();
|
RouteCollection::getInstance()->crawl(DIR_APP)->loadRoutes();
|
||||||
RouteCollection::getInstance()->submit();
|
RouteCollection::getInstance()->submit();
|
||||||
|
|||||||
+2
-3
@@ -4,8 +4,7 @@ define('APP_LANG', 'pt_br');
|
|||||||
|
|
||||||
define('DIR_CONFIG', __DIR__.'/');
|
define('DIR_CONFIG', __DIR__.'/');
|
||||||
define('DIR_ROOT', __DIR__.'/../');
|
define('DIR_ROOT', __DIR__.'/../');
|
||||||
define('DIR_APPLICATION', DIR_ROOT . 'application/');
|
define('DIR_APP', DIR_ROOT . 'app/');
|
||||||
define('DIR_MODULE', DIR_APPLICATION . 'module/');
|
|
||||||
|
|
||||||
define('TEMPLATE_DEFAULT', 'Dashboard');
|
define('TEMPLATE_DEFAULT', 'Dashboard');
|
||||||
//define('TEMPLATE_DEFAULT', 'DefaultTemplate');
|
//define('TEMPLATE_DEFAULT', 'DefaultTemplate');
|
||||||
@@ -14,4 +13,4 @@ define('TEMPLATE_FILETYPE', '.mustache');
|
|||||||
|
|
||||||
define('INSTALL_REQUIRE', FALSE);
|
define('INSTALL_REQUIRE', FALSE);
|
||||||
|
|
||||||
define('CACHE_LANG', FALSE);
|
define('CACHE_LANG', FALSE);
|
||||||
|
|||||||
+21
-2
@@ -1,5 +1,24 @@
|
|||||||
<?php
|
<?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 {
|
class Connection {
|
||||||
|
|
||||||
private function __construct() {
|
private function __construct() {
|
||||||
@@ -96,7 +115,7 @@ class Lang {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$rdi = new RecursiveDirectoryIterator(DIR_APPLICATION);
|
$rdi = new RecursiveDirectoryIterator(DIR_APP);
|
||||||
foreach (new RecursiveIteratorIterator($rdi) as $file) {
|
foreach (new RecursiveIteratorIterator($rdi) as $file) {
|
||||||
if (preg_match("/lang\/.*\.php$/", $file)) {
|
if (preg_match("/lang\/.*\.php$/", $file)) {
|
||||||
$included_lang = explode('/', $file);
|
$included_lang = explode('/', $file);
|
||||||
@@ -113,4 +132,4 @@ class Lang {
|
|||||||
|
|
||||||
abstract class Controller {
|
abstract class Controller {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user