diff --git a/system/engine/action.php b/system/engine/action.php index 01d54ff..8006c92 100644 --- a/system/engine/action.php +++ b/system/engine/action.php @@ -8,40 +8,14 @@ namespace Phacil\Framework; -use Phacil\Framework\Interfaces\Action as ActionInterface; +use \Phacil\Framework\Interfaces\Action as ActionInterface; +use \Phacil\Framework\Traits\Action as ActionTrait; /** @package Phacil\Framework */ final class Action implements ActionInterface { - /** - * - * @var string - */ - protected $file; - - /** - * - * @var string - */ - protected $class; - - /** - * - * @var string - */ - protected $method; - - /** - * - * @var array - */ - protected $args = array(); - - /** - * - * @var (string[]|string|null)[] - */ - private $classAlt = []; + use ActionTrait; + /** * @param string $route * @param array $args @@ -145,79 +119,14 @@ final class Action implements ActionInterface { } - /** @return string */ - public function getFile():string { - return $this->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; - } } /** @package Phacil\Framework */ final class ActionSystem implements ActionInterface { - /** - * - * @var string - */ - protected $file; - - /** - * - * @var string - */ - protected $class; - - /** - * - * @var string - */ - protected $method; - - /** - * - * @var array - */ - protected $args = array(); - - /** - * - * @var (string[]|string|null)[] - */ - private $classAlt = []; + use ActionTrait; /** * @param string $route @@ -269,38 +178,4 @@ final class ActionSystem implements ActionInterface { } } - /** @return string */ - public function getFile():string { - return $this->file; - } - - /** @return string */ - public function getClass():string { - return $this->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; - } } diff --git a/system/engine/autoload.php b/system/engine/autoload.php index 276d723..b9c5115 100644 --- a/system/engine/autoload.php +++ b/system/engine/autoload.php @@ -51,12 +51,13 @@ spl_autoload_register(function ($class) { 'abstracthelper', 'interfaces\\front', 'interfaces\\loader', - 'interfaces\\action' + 'interfaces\\action', + 'traits\\action' ]; if($namespace[0] == "Phacil" && in_array($classNative, $allowed)){ try { - include_once(DIR_SYSTEM . 'engine/'. str_replace("\\", "/", $classNative).'.php'); + require_once(DIR_SYSTEM . 'engine/'. str_replace("\\", "/", $classNative).'.php'); return; } catch (\Exception $th) { $log = new \Phacil\Framework\Log(DIR_LOGS."exception.log"); 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