From 945df2cf087b2ca64c2c9604095880a918ae11a3 Mon Sep 17 00:00:00 2001 From: Julien Turbide Date: Thu, 29 Feb 2024 11:06:08 -0500 Subject: [PATCH] format & refactoring --- src/Mvc/Controller/Behavior.php | 8 +++----- src/Mvc/Controller/Rest/Actions/GetAction.php | 4 ++-- src/Mvc/Controller/Rest/Actions/GetListAction.php | 6 +++--- src/Mvc/Controller/Rest/Actions/IndexAction.php | 12 ++++-------- src/Mvc/Controller/Rest/Actions/NewAction.php | 8 ++++++-- 5 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/Mvc/Controller/Behavior.php b/src/Mvc/Controller/Behavior.php index 486f7d20..2be4f4b8 100644 --- a/src/Mvc/Controller/Behavior.php +++ b/src/Mvc/Controller/Behavior.php @@ -11,9 +11,8 @@ namespace Zemit\Mvc\Controller; +use Phalcon\Di\Injectable; use Phalcon\Events\Manager; -use Phalcon\Mvc\Dispatcher; -use Zemit\Di\Injectable; use Zemit\Mvc\Controller\AbstractTrait\AbstractInjectable; trait Behavior @@ -29,7 +28,7 @@ public function beforeExecuteRoute(): void // $this->eventsManager->collectResponses(true); // retrieve events based on the config roles and features - $permissions = $this->config->get('permissions')->toArray() ?? []; + $permissions = $this->config->pathToArray('permissions') ?? []; $featureList = $permissions['features'] ?? []; $roleList = $permissions['roles'] ?? []; @@ -72,8 +71,7 @@ public function attachBehavior(string $behavior, string $eventType = 'rest'): vo { $event = new $behavior(); - // inject DI - if (method_exists($event, 'setDI')) { + if ($event instanceof Injectable) { $event->setDI($this->getDI()); } diff --git a/src/Mvc/Controller/Rest/Actions/GetAction.php b/src/Mvc/Controller/Rest/Actions/GetAction.php index 7140ca36..dea8d47e 100644 --- a/src/Mvc/Controller/Rest/Actions/GetAction.php +++ b/src/Mvc/Controller/Rest/Actions/GetAction.php @@ -14,8 +14,8 @@ use Phalcon\Http\ResponseInterface; use Zemit\Mvc\Controller\AbstractTrait\AbstractInjectable; -trait GetAction { - +trait GetAction +{ use AbstractInjectable; /** diff --git a/src/Mvc/Controller/Rest/Actions/GetListAction.php b/src/Mvc/Controller/Rest/Actions/GetListAction.php index ad09dd30..0c12e3bb 100644 --- a/src/Mvc/Controller/Rest/Actions/GetListAction.php +++ b/src/Mvc/Controller/Rest/Actions/GetListAction.php @@ -14,8 +14,8 @@ use Phalcon\Http\ResponseInterface; use Zemit\Mvc\Controller\AbstractTrait\AbstractInjectable; -trait GetListAction { - +trait GetListAction +{ use AbstractInjectable; /** @@ -37,7 +37,7 @@ public function getListAction(): ResponseInterface $find = $this->getFind() ?: []; $totalCount = $model::count($this->getFindCount($find)); - $totalCount = is_countable($totalCount)? count($totalCount) : (int)$totalCount; + $totalCount = is_countable($totalCount) ? count($totalCount) : (int)$totalCount; $this->view->setVars([ 'list' => $this->listExpose($model::findWith($with, $find)), 'totalCount' => $totalCount, diff --git a/src/Mvc/Controller/Rest/Actions/IndexAction.php b/src/Mvc/Controller/Rest/Actions/IndexAction.php index 617650a2..07139238 100644 --- a/src/Mvc/Controller/Rest/Actions/IndexAction.php +++ b/src/Mvc/Controller/Rest/Actions/IndexAction.php @@ -22,6 +22,7 @@ trait IndexAction /** * @throws Exception + * @throws \Phalcon\Filter\Exception */ public function indexAction(): ResponseInterface { @@ -32,6 +33,7 @@ public function indexAction(): ResponseInterface /** * @throws Exception + * @throws \Phalcon\Filter\Exception */ protected function restForwarding(): bool { @@ -45,14 +47,8 @@ protected function restForwarding(): bool return true; } else if ($this->request->isGet()) { - if (is_null($id)) { - $this->dispatcher->forward(['action' => 'getList']); - return true; - } - else { - $this->dispatcher->forward(['action' => 'get']); - return true; - } + $this->dispatcher->forward(['action' => is_null($id) ? 'getList' : 'get']); + return true; } return false; } diff --git a/src/Mvc/Controller/Rest/Actions/NewAction.php b/src/Mvc/Controller/Rest/Actions/NewAction.php index 2c69f265..cbb1a565 100644 --- a/src/Mvc/Controller/Rest/Actions/NewAction.php +++ b/src/Mvc/Controller/Rest/Actions/NewAction.php @@ -15,10 +15,14 @@ use Phalcon\Http\ResponseInterface; use Phalcon\Mvc\ModelInterface; use Zemit\Mvc\Controller\AbstractTrait\AbstractInjectable; +use Zemit\Mvc\Controller\Rest\Expose; +use Zemit\Mvc\Controller\Params; -trait NewAction { - +trait NewAction +{ use AbstractInjectable; + use Params; + use Expose; /** * Prepare a new unsaved model