diff --git a/system/engine/action.php b/system/engine/action.php index e3d70aa..9792fdf 100644 --- a/system/engine/action.php +++ b/system/engine/action.php @@ -19,14 +19,69 @@ use \Phacil\Framework\Config; * * @package Phacil\Framework **/ -final class Action implements ActionInterface { +class Action implements ActionInterface { use ActionTrait; - + /** * @inheritdoc */ - public function __construct($route, $args = array()) { + public function __construct($route, $args = array(), $local = self::APP) { + if($local == self::APP) { + $this->normal($route, $args); + } + if($local == self::SYSTEM) { + $this->system($route, $args); + } + } + + private function system($route, $args = array()) + { + $path = ''; + + $parts = explode('/', str_replace('../', '', (string)$route)); + + foreach ($parts as $part) { + $path .= $part; + + if (is_dir(Config::DIR_SYSTEM() . '' . $path)) { + $path .= '/'; + + array_shift($parts); + + continue; + } + + if (is_file(Config::DIR_SYSTEM() . '' . str_replace('../', '', $path) . '.php')) { + $this->file = Config::DIR_SYSTEM() . '' . str_replace('../', '', $path) . '.php'; + + $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; + } + } + + if ($args) { + $this->args = $args; + } + + $method = array_shift($parts); + + if ($method) { + $this->method = $method; + } else { + $this->method = 'index'; + } + } + + private function normal($route, $args = array()) { $path = ''; $pathC = ""; @@ -164,65 +219,3 @@ final class Action implements ActionInterface { } - - -/** - * Action class to route all framework system controllers - * - * @since 1.0.1 - * - * @package Phacil\Framework - */ -final class ActionSystem implements ActionInterface { - - use ActionTrait; - - /** - * @inheritdoc - */ - public function __construct($route, $args = array()) { - $path = ''; - - $parts = explode('/', str_replace('../', '', (string)$route)); - - foreach ($parts as $part) { - $path .= $part; - - if (is_dir(Config::DIR_SYSTEM() . '' . $path)) { - $path .= '/'; - - array_shift($parts); - - continue; - } - - if (is_file(Config::DIR_SYSTEM() . '' . str_replace('../', '', $path) . '.php')) { - $this->file = Config::DIR_SYSTEM() . '' . str_replace('../', '', $path) . '.php'; - - $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; - } - } - - if ($args) { - $this->args = $args; - } - - $method = array_shift($parts); - - if ($method) { - $this->method = $method; - } else { - $this->method = 'index'; - } - } - -} diff --git a/system/engine/actionsystem.php b/system/engine/actionsystem.php new file mode 100644 index 0000000..0a34b44 --- /dev/null +++ b/system/engine/actionsystem.php @@ -0,0 +1,76 @@ +file = Config::DIR_SYSTEM() . '' . str_replace('../', '', $path) . '.php'; + + $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; + } + } + + if ($args) { + $this->args = $args; + } + + $method = array_shift($parts); + + if ($method) { + $this->method = $method; + } else { + $this->method = 'index'; + } + } +} \ No newline at end of file diff --git a/system/engine/autoload.php b/system/engine/autoload.php index 032dffd..c712b83 100644 --- a/system/engine/autoload.php +++ b/system/engine/autoload.php @@ -82,6 +82,7 @@ 'Response', 'Classes', 'AbstractHelper', + 'ActionSystem', 'Interfaces\\Front', 'Interfaces\\Loader', 'Interfaces\\Action', @@ -331,7 +332,7 @@ private function loadActionClasses() { if (!self::isPhacil()) return false; - if(self::$class != 'Phacil\Framework\Action' && self::$class != 'Phacil\Framework\ActionSystem') return false; + if(self::$class != 'Phacil\Framework\Action') return false; $file = (\Phacil\Framework\Config::DIR_SYSTEM() . 'engine/action.php'); diff --git a/system/engine/controller.php b/system/engine/controller.php index 030a862..388be3f 100644 --- a/system/engine/controller.php +++ b/system/engine/controller.php @@ -268,11 +268,7 @@ abstract class Controller implements \Phacil\Framework\Interfaces\Controller { $tpl = new \Phacil\Framework\Render($this->registry); - $pegRout = explode("/", ($this->registry->routeOrig)?: Request::GET('route')); - /* $pegRoutWithoutLast = $pegRout; - array_pop($pegRoutWithoutLast); - $pegRoutWithoutPenultimate = $pegRoutWithoutLast; - array_pop($pegRoutWithoutPenultimate); */ + $pegRout = explode("/", ($this->registry->routeOrig)?: \Phacil\Framework\startEngineExacTI::getRoute()); if($this->template === NULL) { $thema = ($this->config->get("config_template") != NULL) ? $this->config->get("config_template") : "default"; @@ -345,11 +341,7 @@ abstract class Controller implements \Phacil\Framework\Interfaces\Controller { $templatePath = str_replace($this->template, "", $filesSeted[0]); } } - /* elseif(file_exists(Config::DIR_APP_MODULAR().implode("/", $pegRoutWithoutLast)."/View/" .$this->template)){ - $templatePath = Config::DIR_APP_MODULAR().implode("/", $pegRoutWithoutLast)."/View/"; - } elseif(file_exists(Config::DIR_APP_MODULAR().implode("/", $pegRoutWithoutPenultimate)."/View/" .$this->template)){ - $templatePath = Config::DIR_APP_MODULAR().implode("/", $pegRoutWithoutPenultimate)."/View/"; - } */ + if(file_exists(Config::DIR_TEMPLATE() .$this->template)){ $templatePath = Config::DIR_TEMPLATE(); } diff --git a/system/engine/interfaces/action.php b/system/engine/interfaces/action.php index b3da199..04297ea 100644 --- a/system/engine/interfaces/action.php +++ b/system/engine/interfaces/action.php @@ -16,12 +16,16 @@ namespace Phacil\Framework\Interfaces; */ interface Action { + const APP = "APP"; + const SYSTEM = "SYSTEM"; + /** * @param string $route HTTP route for the respective controller - * @param array $args Args to be pass for the method controller + * @param array $args (Optional) Args to be pass for the method controller + * @param string $local (Optional) Set if the action is a system or app controller * @return void */ - public function __construct($route, $args = array()); + public function __construct($route, $args = array(), $local = self::APP); /** * Return the controller file path diff --git a/system/system.php b/system/system.php index 29398f4..9556e35 100644 --- a/system/system.php +++ b/system/system.php @@ -543,7 +543,7 @@ $engine->extraRegistrations(); $frontController = new Front($engine->registry); // SEO URL's -$frontController->addPreAction(new ActionSystem((string) 'url/seo_url')); +$frontController->addPreAction(new Action((string) 'url/seo_url', [], \Phacil\Framework\Interfaces\Action::SYSTEM)); //extraPreActions if($engine->controllerPreActions()){