diff --git a/README.md b/README.md index e0fedf7..f41fc57 100644 --- a/README.md +++ b/README.md @@ -592,9 +592,10 @@ In a sample case, we have this controller: ##### Sample: ```php - define("ROUTES", array( + define("ROUTES", [ "produto/%d/%/promo" => "feriado/natal/presentes" - ) + ] + ); ``` ```php diff --git a/public_html/index.php b/public_html/index.php index 651cb25..342c6e9 100644 --- a/public_html/index.php +++ b/public_html/index.php @@ -1,7 +1,7 @@ dirCache . preg_replace('/[^A-Z0-9\._-]/i', '', $key) . '.cache'); @@ -155,6 +163,7 @@ final class Caches { } } + /** @return true */ public function deleteAll() { $files = glob($this->dirCache . '*.cache'); @@ -165,13 +174,15 @@ final class Caches { return true; } + /** @return bool */ public function clear() { return $this->deleteAll(); } + /** @return Phacil\Framework\stdClass */ public function stats() { - $obj = new stdClass(); + $obj = new \stdClass(); $obj->size = $this->GetDirectorySize($this->dirCache); $obj->info = NULL; @@ -181,6 +192,10 @@ final class Caches { return $obj; } + /** + * @param string $path + * @return float|int + */ private function GetDirectorySize($path){ $bytestotal = 0; $path = realpath($path); diff --git a/system/engine/action.php b/system/engine/action.php index ef3fc2b..8006c92 100644 --- a/system/engine/action.php +++ b/system/engine/action.php @@ -8,13 +8,14 @@ namespace Phacil\Framework; +use \Phacil\Framework\Interfaces\Action as ActionInterface; +use \Phacil\Framework\Traits\Action as ActionTrait; + /** @package Phacil\Framework */ -final class Action { - protected $file; - protected $class; - protected $method; - protected $args = array(); +final class Action implements ActionInterface { + use ActionTrait; + /** * @param string $route * @param array $args @@ -42,34 +43,61 @@ final class Action { array_shift($parts); continue; - }elseif (is_dir(DIR_APPLICATION . 'controller' . $path)) { + }elseif (is_dir(DIR_APPLICATION . 'controller/' . $path)) { $path .= '/'; array_shift($parts); continue; } + + $strReplaceOnPathNew = str_replace('../', '', $pathNew); + $strReplaceOnPath = str_replace('../', '', $path); + $strReplaceOnPart = str_replace('../', '', $part); + $pregReplaceOnPath = preg_replace('/[^a-zA-Z0-9]/', '', $path); + $pregReplaceOnPart = preg_replace('/[^a-zA-Z0-9]/', '', $part); - if (is_file(DIR_APP_MODULAR . str_replace('../', '', $pathNew) . 'Controller/' . str_replace('../', '', $part) . '.php')) { - $this->file = DIR_APP_MODULAR . str_replace('../', '', $pathNew) . 'Controller/' . str_replace('../', '', $part) . '.php'; + if (is_file(DIR_APP_MODULAR . $strReplaceOnPathNew . 'Controller/' . $strReplaceOnPart . '.php')) { + $this->file = DIR_APP_MODULAR . $strReplaceOnPathNew . 'Controller/' . $strReplaceOnPart . '.php'; - $this->class = 'Controller' . preg_replace('/[^a-zA-Z0-9]/', '', $path); + $this->class = 'Controller' . $pregReplaceOnPath; + + $this->classAlt = [ + 'class' => $this->mountClass($strReplaceOnPathNew, $pregReplaceOnPart), + 'legacy' => $this->class, + 'ucfirst' => ucfirst($pregReplaceOnPart), + 'direct' => $pregReplaceOnPart + ]; array_shift($parts); break; - } elseif (is_file(DIR_APP_MODULAR . str_replace('../', '', $pathNew) . 'Controller/' . str_replace('../', '', ucfirst($part)) . '.php')) { - $this->file = DIR_APP_MODULAR . str_replace('../', '', $pathNew) . 'Controller/' . str_replace('../', '', ucfirst($part)) . '.php'; + } elseif (is_file(DIR_APP_MODULAR . $strReplaceOnPathNew . 'Controller/' . ucfirst($strReplaceOnPart) . '.php')) { + $this->file = DIR_APP_MODULAR . $strReplaceOnPathNew . 'Controller/' . ucfirst($strReplaceOnPart) . '.php'; - $this->class = 'Controller' . preg_replace('/[^a-zA-Z0-9]/', '', $path); + $this->class = 'Controller' . $pregReplaceOnPath; + + $this->classAlt = [ + 'class' => $this->mountClass($strReplaceOnPathNew, $pregReplaceOnPart), + 'legacy' => $this->class, + 'ucfirst' => ucfirst($pregReplaceOnPart), + 'direct' => $pregReplaceOnPart + ]; array_shift($parts); break; - } elseif (is_file(DIR_APPLICATION . 'controller/' . str_replace('../', '', $path) . '.php')) { - $this->file = DIR_APPLICATION . 'controller/' . str_replace('../', '', $path) . '.php'; + } elseif (is_file(DIR_APPLICATION . 'controller/' . $strReplaceOnPath . '.php')) { + $this->file = DIR_APPLICATION . 'controller/' . $strReplaceOnPath . '.php'; - $this->class = 'Controller' . preg_replace('/[^a-zA-Z0-9]/', '', $path); + $this->class = 'Controller' . $pregReplaceOnPath; + + $this->classAlt = [ + 'class' => $this->mountClass($strReplaceOnPathNew, $pregReplaceOnPart), + 'legacy' => $this->class, + 'ucfirst' => ucfirst($pregReplaceOnPart), + 'direct' => $pregReplaceOnPart + ]; array_shift($parts); @@ -91,34 +119,14 @@ final class Action { } - /** @return string */ - public function getFile() { - return $this->file; - } - - /** @return string */ - public function getClass() { - return $this->class; - } - - /** @return string */ - public function getMethod() { - return $this->method; - } - /** @return array */ - public function getArgs() { - return $this->args; - } } /** @package Phacil\Framework */ -final class ActionSystem { - protected $file; - protected $class; - protected $method; - protected $args = array(); +final class ActionSystem implements ActionInterface { + + use ActionTrait; /** * @param string $route @@ -146,6 +154,11 @@ final class ActionSystem { $this->class = 'System' . preg_replace('/[^a-zA-Z0-9]/', '', $path); + $this->classAlt = [ + 'legacy' => $this->class, + 'direct' => preg_replace('/[^a-zA-Z0-9]/', '', $part) + ]; + array_shift($parts); break; @@ -165,23 +178,4 @@ final class ActionSystem { } } - /** @return string */ - public function getFile() { - return $this->file; - } - - /** @return string */ - public function getClass() { - return $this->class; - } - - /** @return string */ - public function getMethod() { - return $this->method; - } - - /** @return array */ - public function getArgs() { - return $this->args; - } } diff --git a/system/engine/autoload.php b/system/engine/autoload.php index 996be67..b9c5115 100644 --- a/system/engine/autoload.php +++ b/system/engine/autoload.php @@ -7,14 +7,10 @@ */ -require_once(DIR_SYSTEM . 'engine/action.php'); -require_once(DIR_SYSTEM . 'engine/controller.php'); - - +/** @autoload class */ spl_autoload_register(function ($class) { $namespace = explode("\\", $class); - - var_dump($class); + $namespaceWithoutPrefix = (defined('NAMESPACE_PREFIX')) ? explode("\\", str_replace(NAMESPACE_PREFIX."\\" , "", $class)) : $namespace; $legacy = [ 'Controller', @@ -29,13 +25,18 @@ spl_autoload_register(function ($class) { ]; if(in_array($class, $legacy)){ - - class_alias("\\Phacil\\Framework\\".$class, $class); + try { + class_alias("\\Phacil\\Framework\\".$class, $class); + } catch (\Exception $th) { + $log = new \Phacil\Framework\Log(DIR_LOGS."exception.log"); + $log->write($class.' not loaded!'); + } + //eval("class ".$class." extends \\Phacil\\Framework\\".$class." {}"); return; } - $class = ($namespace[0] == "Phacil") ? str_replace('phacil\\framework\\', '', strtolower( $class)) : $class; + $classNative = ($namespace[0] == "Phacil") ? str_replace('phacil\\framework\\', '', strtolower( $class)) : $class; $allowed = [ 'log', @@ -47,19 +48,25 @@ spl_autoload_register(function ($class) { 'document', 'response', 'classes', - 'abstracthelper' + 'abstracthelper', + 'interfaces\\front', + 'interfaces\\loader', + 'interfaces\\action', + 'traits\\action' ]; - if($namespace[0] == "Phacil" && in_array($class, $allowed)){ + if($namespace[0] == "Phacil" && in_array($classNative, $allowed)){ try { - include_once(DIR_SYSTEM . 'engine/'. $class.'.php'); + require_once(DIR_SYSTEM . 'engine/'. str_replace("\\", "/", $classNative).'.php'); return; - } catch (\Throwable $th) { + } catch (\Exception $th) { + $log = new \Phacil\Framework\Log(DIR_LOGS."exception.log"); + $log->write($class.' not loaded!'); throw new \Exception("Class '$class' not loaded."); } } - $value = DIR_SYSTEM . $class.'/autoload.php'; + $value = DIR_SYSTEM . $classNative.'/autoload.php'; if($namespace[0] == "Phacil" && in_array($value, $this->dirs)){ try { @@ -67,9 +74,13 @@ spl_autoload_register(function ($class) { require_once $value; return; } else { + $log = new \Phacil\Framework\Log(DIR_LOGS."exception.log"); + $log->write($class.' not loaded!'); throw new \Exception("I can't load '$value' file! Please check system permissions."); } } catch (\Exception $e) { + $log = new \Phacil\Framework\Log(DIR_LOGS."exception.log"); + $log->write($class.' not loaded!'); exit($e->getMessage()); } } @@ -81,9 +92,31 @@ spl_autoload_register(function ($class) { require_once $tryMagicOne; return; } else { + $log = new \Phacil\Framework\Log(DIR_LOGS."exception.log"); + $log->write($class.' not loaded!'); + throw new \Exception("I can't load '$tryMagicOne' file! Please check system permissions."); + } + } catch (\Exception $e) { + $log = new \Phacil\Framework\Log(DIR_LOGS."exception.log"); + $log->write($class.' not loaded!'); + exit($e->getMessage()); + } + } + + + if(file_exists($tryMagicOne = DIR_APP_MODULAR. implode("/", $namespaceWithoutPrefix).".php")){ + try { + if(is_readable($tryMagicOne)) { + require_once $tryMagicOne; + return; + } else { + $log = new \Phacil\Framework\Log(DIR_LOGS."exception.log"); + $log->write($class.' not loaded!'); throw new \Exception("I can't load '$tryMagicOne' file! Please check system permissions."); } } catch (\Exception $e) { + $log = new \Phacil\Framework\Log(DIR_LOGS."exception.log"); + $log->write($class.' not loaded!'); exit($e->getMessage()); } } @@ -96,15 +129,21 @@ spl_autoload_register(function ($class) { require_once $tryMagicOne; return; } else { + $log = new \Phacil\Framework\Log(DIR_LOGS."exception.log"); + $log->write($class.' not loaded!'); throw new \Exception("I can't load '$tryMagicOne' file! Please check system permissions."); } } catch (\Exception $e) { + $log = new \Phacil\Framework\Log(DIR_LOGS."exception.log"); + $log->write($class.' not loaded!'); exit($e->getMessage()); } } + return; }); - +require_once(DIR_SYSTEM . 'engine/action.php'); +//require_once(DIR_SYSTEM . 'engine/controller.php'); //require_once(DIR_SYSTEM . 'engine/legacy.php'); \ No newline at end of file diff --git a/system/engine/controller.php b/system/engine/controller.php index b4eff9b..f7e6aef 100644 --- a/system/engine/controller.php +++ b/system/engine/controller.php @@ -14,15 +14,42 @@ use RuntimeException; use SmartyException; use Exception; -/** @package Phacil\Framework */ +/** + * Extend this class to create interation with your module controller to Phacil engine controller. + * + * Use as: + * class YouClass extends \Phacil\Framework\Controller {} + * + * You can use the __construct function on call the \Phacil\Framework\Register object inside parent. + * + * Example: public funcion __construct(\Phacil\Framework\Registry $registry){ parent::__construct($registry); YOUR_CODE; } + * + * @package Phacil\Framework + * @since 1.0 + * */ abstract class Controller { /** * * @var Registry */ protected $registry; + + /** + * + * @var int + */ protected $id; + + /** + * + * @var mixed + */ protected $layout; + + /** + * + * @var string + */ protected $template; /** @@ -49,26 +76,47 @@ abstract class Controller { */ protected $error = array(); + /** + * + * @var string + */ protected $output; /** * * @var string[] */ - public $templateTypes = ["tpl", "twig", "mustache", "smarty", "dwoo"]; + public $templateTypes = ["tpl", "twig", "mustache", "smarty", "phtml"]; + + public $routeOrig; /** + * Implements constructor. + * + * If you use this, don't forget the parent::__construct($registry); + * * @param \Phacil\Framework\Registry $registry * @return void */ - public function __construct($registry) { + public function __construct(\Phacil\Framework\Registry $registry) { $this->registry = $registry; } + /** + * + * @param string $key + * @return Registry + */ public function __get($key) { return $this->registry->get($key); } + /** + * + * @param string $key + * @param object $value + * @return void + */ public function __set($key, $value) { $this->registry->set($key, $value); } @@ -76,7 +124,7 @@ abstract class Controller { /** * @param string $route * @param array $args - * @return Action + * @return \Phacil\Framework\Interfaces\Action */ protected function forward($route, array $args = array()) { return new Action($route, $args); @@ -96,21 +144,35 @@ abstract class Controller { /** * @param string $child * @param array $args - * @return mixed + * @return object */ protected function getChild($child, array $args = array()) { $action = new Action($child, $args); $file = $action->getFile(); $class = $action->getClass(); + $classAlt = $action->getClassAlt(); $method = $action->getMethod(); if (file_exists($file)) { require_once($file); - $controller = new $class($this->registry); + foreach($classAlt as $classController){ + try { + if(class_exists($classController)){ + $this->registry->routeOrig = $child; + $controller = new $classController($this->registry); + + break; + } + } catch (\Throwable $th) { + //throw $th; + } + } $controller->$method($args); + $this->registry->routeOrig = null; + return $controller->output; } else { trigger_error('Error: Could not load controller ' . $child . '!'); @@ -119,7 +181,7 @@ abstract class Controller { } /** - * @return mixed + * @return string * @throws TypeError * @throws Mustache_Exception_UnknownTemplateException * @throws RuntimeException @@ -132,41 +194,74 @@ abstract class Controller { $this->data[basename($child)] = $this->getChild($child); } + $pegRout = explode("/", ($this->registry->routeOrig)?: $this->request->get['route']); + $pegRoutWithoutLast = $pegRout; + array_pop($pegRoutWithoutLast); + $pegRoutWithoutPenultimate = $pegRoutWithoutLast; + array_pop($pegRoutWithoutPenultimate); + if($this->template === NULL) { - $pegRout = explode("/", $this->request->get['route']); $thema = ($this->config->get("config_template") != NULL) ? $this->config->get("config_template") : "default"; + $structure = []; foreach($this->templateTypes as $extensionTemplate) { - $structure = $thema.'/'.$pegRout[0].'/'.$pegRout[1].((isset($pegRout[2])) ? '_'.$pegRout[2] : '').'.'.$extensionTemplate; - $structure_D = 'default/'.$pegRout[0].'/'.$pegRout[1].((isset($pegRout[2])) ? '_'.$pegRout[2] : '').'.'.$extensionTemplate; - $structure_W = $pegRout[0].'/'.$pegRout[1].((isset($pegRout[2])) ? '_'.$pegRout[2] : '').'.'.$extensionTemplate; + $structure[] = $thema.'/'.$pegRout[0].'/'.$pegRout[1].((isset($pegRout[2])) ? '_'.$pegRout[2] : '').'.'.$extensionTemplate; + $structure[] = 'default/'.$pegRout[0].'/'.$pegRout[1].((isset($pegRout[2])) ? '_'.$pegRout[2] : '').'.'.$extensionTemplate; + $structure[] = $pegRout[0].'/'.$pegRout[1].((isset($pegRout[2])) ? '_'.$pegRout[2] : '').'.'.$extensionTemplate; + $structure[] = implode("/", $pegRoutWithoutLast).'/View/'.end($pegRout).'.'.$extensionTemplate; + $structure[] = implode("/", $pegRoutWithoutPenultimate).'/View/'.((isset($pegRout[count($pegRout)-2])) ? $pegRout[count($pegRout)-2]."_".end($pegRout) : end($pegRout)).'.'.$extensionTemplate; - if (file_exists(DIR_TEMPLATE .$structure) != false) { - $this->template = $structure; - break; - } elseif (file_exists(DIR_TEMPLATE .$structure_D)){ - $this->template = $structure_D; - break; - } elseif(file_exists(DIR_TEMPLATE .$structure_W)) { - $this->template = $structure_W; - break; - } + foreach($structure as $themefile){ + if(file_exists(DIR_APP_MODULAR .$themefile)){ + $this->template = $themefile; + $templatePath = DIR_APP_MODULAR; + break; + } + if(file_exists(DIR_TEMPLATE .$themefile)){ + $this->template = $themefile; + $templatePath = DIR_TEMPLATE; + break; + } + } + + } + } else { + //$teste = DIR_APP_MODULAR.implode("/", $pegRoutWithoutLast)."/View/" .$this->template; + if(file_exists(DIR_APP_MODULAR.implode("/", $pegRoutWithoutLast)."/View/" .$this->template)){ + $templatePath = DIR_APP_MODULAR.implode("/", $pegRoutWithoutLast)."/View/"; + } elseif(file_exists(DIR_APP_MODULAR.implode("/", $pegRoutWithoutPenultimate)."/View/" .$this->template)){ + $templatePath = DIR_APP_MODULAR.implode("/", $pegRoutWithoutPenultimate)."/View/"; + } + if(file_exists(DIR_TEMPLATE .$this->template)){ + $templatePath = DIR_TEMPLATE; } } - if (file_exists(DIR_TEMPLATE . $this->template)) { + if (file_exists($templatePath . $this->template)) { - $templateType = substr(strrchr($this->template, '.'), 1); + $templateFileInfo = pathinfo($templatePath .$this->template); + $templateType = $templateFileInfo['extension']; switch($templateType) { case 'tpl': extract($this->data); ob_start(); - require(DIR_TEMPLATE . $this->template); + require($templatePath . $this->template); + + $this->output = ob_get_contents(); + + ob_end_clean(); + break; + + case 'phtml': + extract($this->data); + + ob_start(); + require($templatePath . $this->template); $this->output = ob_get_contents(); @@ -176,6 +271,9 @@ abstract class Controller { case 'twig': require_once(DIR_SYSTEM."templateEngines/Twig/autoload.php"); + /** + * @var array + */ $config = array( 'autoescape' => false, 'cache' => DIR_CACHE."twig/", @@ -183,16 +281,26 @@ abstract class Controller { ); $TwigLoaderFilesystem = constant('\TwigLoaderFilesystem'); $Twig_Environment = constant('\TwigEnvironment'); - $Twig_SimpleFilter = constant('TwigSimpleFilter'); - $Twig_Extension_Debug = constant('TwigExtensionDebug'); + $Twig_SimpleFilter = constant('\TwigSimpleFilter'); + $Twig_Extension_Debug = constant('\TwigExtensionDebug'); + + /** + * @var \TwigLoaderFilesystem + */ + $loader = new $TwigLoaderFilesystem ($templatePath); - $loader = new $TwigLoaderFilesystem (DIR_TEMPLATE); + /** + * @var \TwigEnvironment + */ $twig = new $Twig_Environment($loader, $config); if($config['debug']) { $twig->addExtension(new $Twig_Extension_Debug()); } + /** + * @var \transExtension + */ $twig->addExtension(new \transExtension()); $twig->addFilter(new $Twig_SimpleFilter('translate', function ($str) { @@ -220,12 +328,15 @@ abstract class Controller { \Mustache_Autoloader::register(); + /** + * @var \Mustache_Engine + */ $mustache = new \Mustache_Engine(array( //'template_class_prefix' => '__MyTemplates_', 'cache' => DIR_CACHE.'mustache', 'cache_file_mode' => 0666, // Please, configure your umask instead of doing this :) //'cache_lambda_templates' => true, - 'loader' => new \Mustache_Loader_FilesystemLoader(DIR_TEMPLATE), + 'loader' => new \Mustache_Loader_FilesystemLoader($templatePath), //'partials_loader' => new Mustache_Loader_FilesystemLoader(dirname(__FILE__).'/views/partials'), 'helpers' => array('translate' => function($text) { if (class_exists('Translate')) { @@ -251,9 +362,12 @@ abstract class Controller { case 'smarty': require_once(DIR_SYSTEM."templateEngines/smarty/autoload.php"); + /** + * @var \Smarty + */ $smarty = new \Smarty(); - $smarty->setTemplateDir(DIR_TEMPLATE); + $smarty->setTemplateDir($templatePath); $smarty->setCompileDir(DIR_CACHE."Smarty/compile/"); //$smarty->setConfigDir('/web/www.example.com/guestbook/configs/'); $smarty->setCacheDir(DIR_CACHE."Smarty/cache/"); @@ -274,7 +388,7 @@ abstract class Controller { extract($this->data); ob_start(); - require(DIR_TEMPLATE . $this->template); + require($templatePath . $this->template); $this->output = ob_get_contents(); @@ -286,18 +400,14 @@ abstract class Controller { return $this->output; } else { - trigger_error('Error: Could not load template ' . DIR_TEMPLATE . $this->template . '!'); + trigger_error('Error: Could not load template ' . $templatePath . $this->template . '!'); exit(); } } /** * @param bool $commonChildren - * @return mixed - * @throws TypeError - * @throws Mustache_Exception_UnknownTemplateException - * @throws RuntimeException - * @throws SmartyException + * @return \Phacil\Framework\Response * @throws Exception */ protected function out ($commonChildren = true) { diff --git a/system/engine/front.php b/system/engine/front.php index ccb7c59..6ef124b 100644 --- a/system/engine/front.php +++ b/system/engine/front.php @@ -8,8 +8,13 @@ namespace Phacil\Framework; +use Phacil\Framework\Interfaces\Front as frontinterface; +use Phacil\Framework\Interfaces\Action; + +use Exception; + /** @package Phacil\Framework */ -final class Front { +final class Front implements frontinterface { /** * @@ -36,20 +41,20 @@ final class Front { /** - * @param ActionSystem $pre_action + * @param \Phacil\Framework\Interfaces\Action $pre_action * @return void */ - public function addPreAction(\Phacil\Framework\ActionSystem $pre_action) { + public function addPreAction(\Phacil\Framework\Interfaces\Action $pre_action) { $this->pre_action[] = $pre_action; } /** * @param Action $action - * @param Action $error + * @param string $error * @return void */ - public function dispatch(\Phacil\Framework\Action $action, \Phacil\Framework\Action $error) { + public function dispatch(\Phacil\Framework\Interfaces\Action $action, $error) { $this->error = $error; foreach ($this->pre_action as $pre_action) { @@ -67,28 +72,56 @@ final class Front { } } - private function execute($action) { + /** + * @param object $action + * @return \Phacil\Framework\Interfaces\Action + * @throws Exception + */ + private function execute(object $action) { $file = $action->getFile(); $class = $action->getClass(); + $classAlt = $action->getClassAlt(); $method = $action->getMethod(); $args = $action->getArgs(); - $action = ''; + unset($action); if (file_exists($file)) { require_once($file); - $controller = new $class($this->registry); + foreach($classAlt as $classController){ + try { + if(class_exists($classController)){ + $controller = new $classController($this->registry); + + break; + } + } catch (\Throwable $th) { + //throw $th; + } + } - if (is_callable(array($controller, $method))) { - $action = call_user_func_array(array($controller, $method), $args); - } else { - $action = $this->error; + try { + if (is_callable(array($controller, $method))) { + $action = call_user_func_array(array($controller, $method), $args); + } else { + $action = new Action($this->error); + + $this->error = ''; + throw new \Exception("The controller can't be loaded", 1); + } + } catch (\Throwable $th) { + //throw $th; + $action = new Action($this->error); $this->error = ''; + + throw new \Exception("The controller can't be loaded", 1); + } + } else { - $action = $this->error; + $action = new Action($this->error); $this->error = ''; } diff --git a/system/engine/interfaces/action.php b/system/engine/interfaces/action.php new file mode 100644 index 0000000..3a18b9c --- /dev/null +++ b/system/engine/interfaces/action.php @@ -0,0 +1,41 @@ +controller($control); } diff --git a/system/engine/registry.php b/system/engine/registry.php index 10f29fa..fe6365c 100644 --- a/system/engine/registry.php +++ b/system/engine/registry.php @@ -12,6 +12,8 @@ final class Registry { private $data = array(); + public $routeOrig; + /** * @param string $key * @return mixed diff --git a/system/engine/traits/action.php b/system/engine/traits/action.php new file mode 100644 index 0000000..4034c91 --- /dev/null +++ b/system/engine/traits/action.php @@ -0,0 +1,86 @@ +file; + } + + /** @return string */ + public function getClass():string { + return $this->class; + } + + private function mountClass(string $namespace, string $class) { + return (defined('NAMESPACE_PREFIX') ? NAMESPACE_PREFIX."\\" : "").str_replace("/", "\\", $namespace)."Controller\\".$class; + } + + /** + * + * @param string $class + * @return $this + */ + public function setClass($class) { + $this->class = $class; + return $this; + } + + /** @return array */ + public function getClassAlt():array { + return $this->classAlt; + } + + /** @return string */ + public function getMethod():string { + return $this->method; + } + + /** @return array */ + public function getArgs():array { + return $this->args; + } +} \ No newline at end of file diff --git a/system/system.php b/system/system.php index 49499a2..c88c71d 100644 --- a/system/system.php +++ b/system/system.php @@ -11,9 +11,11 @@ namespace Phacil\Framework; use Exception; use TypeError; +/** + * + * @package Phacil\Framework + */ class startEngineExacTI { - /*public $constants; - public $userConstants;*/ /** * @@ -240,6 +242,7 @@ $loader = new Loader($engine->registry); $engine->registry->set('load', $loader); // Config +/** @var Config */ $config = new Config(); $engine->registry->set('config', $config); @@ -405,7 +408,7 @@ if (isset($request->get['route'])) { // Dispatch $not_found = (defined('NOT_FOUND')) ? NOT_FOUND : 'error/not_found'; -$controller->dispatch($action, new Action($not_found)); +$controller->dispatch($action, ($not_found)); // Output $response->output();