From d01ca5c256ccaf1f9ecdf1e9e50dad310b781597 Mon Sep 17 00:00:00 2001 From: "Bruno O. Notario" Date: Fri, 30 Jul 2021 12:28:23 -0300 Subject: [PATCH] More interfaces --- system/engine/action.php | 69 ++++++++++++++++++++++++----- system/engine/autoload.php | 11 +++-- system/engine/controller.php | 2 +- system/engine/front.php | 9 ++-- system/engine/interfaces/action.php | 41 +++++++++++++++++ system/engine/interfaces/front.php | 8 ++-- system/engine/interfaces/loader.php | 36 +++++++-------- 7 files changed, 131 insertions(+), 45 deletions(-) create mode 100644 system/engine/interfaces/action.php diff --git a/system/engine/action.php b/system/engine/action.php index e6c2d7d..01d54ff 100644 --- a/system/engine/action.php +++ b/system/engine/action.php @@ -8,13 +8,38 @@ namespace Phacil\Framework; +use Phacil\Framework\Interfaces\Action as ActionInterface; + /** @package Phacil\Framework */ -final class Action { +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 = []; /** @@ -121,12 +146,12 @@ final class Action { } /** @return string */ - public function getFile() { + public function getFile():string { return $this->file; } /** @return string */ - public function getClass() { + public function getClass():string { return $this->class; } @@ -145,27 +170,47 @@ final class Action { } /** @return array */ - public function getClassAlt() { + public function getClassAlt():array { return $this->classAlt; } /** @return string */ - public function getMethod() { + public function getMethod():string { return $this->method; } /** @return array */ - public function getArgs() { + public function getArgs():array { return $this->args; } } /** @package Phacil\Framework */ -final class ActionSystem { +final class ActionSystem implements ActionInterface { + + /** + * + * @var string + */ protected $file; + + /** + * + * @var string + */ protected $class; + + /** + * + * @var string + */ protected $method; + + /** + * + * @var array + */ protected $args = array(); /** @@ -225,12 +270,12 @@ final class ActionSystem { } /** @return string */ - public function getFile() { + public function getFile():string { return $this->file; } /** @return string */ - public function getClass() { + public function getClass():string { return $this->class; } @@ -245,17 +290,17 @@ final class ActionSystem { } /** @return array */ - public function getClassAlt() { + public function getClassAlt():array { return $this->classAlt; } /** @return string */ - public function getMethod() { + public function getMethod():string { return $this->method; } /** @return array */ - public function getArgs() { + public function getArgs():array { return $this->args; } } diff --git a/system/engine/autoload.php b/system/engine/autoload.php index 9a80eed..276d723 100644 --- a/system/engine/autoload.php +++ b/system/engine/autoload.php @@ -7,9 +7,6 @@ */ -require_once(DIR_SYSTEM . 'engine/action.php'); -require_once(DIR_SYSTEM . 'engine/controller.php'); - /** @autoload class */ spl_autoload_register(function ($class) { $namespace = explode("\\", $class); @@ -52,8 +49,9 @@ spl_autoload_register(function ($class) { 'response', 'classes', 'abstracthelper', - 'interfaces\front', - 'interfaces\loader' + 'interfaces\\front', + 'interfaces\\loader', + 'interfaces\\action' ]; if($namespace[0] == "Phacil" && in_array($classNative, $allowed)){ @@ -145,5 +143,6 @@ spl_autoload_register(function ($class) { }); - +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 2366f12..f7e6aef 100644 --- a/system/engine/controller.php +++ b/system/engine/controller.php @@ -124,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); diff --git a/system/engine/front.php b/system/engine/front.php index 4b0af5e..6ef124b 100644 --- a/system/engine/front.php +++ b/system/engine/front.php @@ -9,6 +9,7 @@ namespace Phacil\Framework; use Phacil\Framework\Interfaces\Front as frontinterface; +use Phacil\Framework\Interfaces\Action; use Exception; @@ -40,10 +41,10 @@ final class Front implements frontinterface { /** - * @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; } @@ -53,7 +54,7 @@ final class Front implements frontinterface { * @param string $error * @return void */ - public function dispatch(\Phacil\Framework\Action $action, $error) { + public function dispatch(\Phacil\Framework\Interfaces\Action $action, $error) { $this->error = $error; foreach ($this->pre_action as $pre_action) { @@ -73,7 +74,7 @@ final class Front implements frontinterface { /** * @param object $action - * @return Action + * @return \Phacil\Framework\Interfaces\Action * @throws Exception */ private function execute(object $action) { 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 @@ +