Skip to content

Commit

Permalink
format & refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
jturbide committed Feb 29, 2024
1 parent 1bee1db commit 945df2c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 20 deletions.
8 changes: 3 additions & 5 deletions src/Mvc/Controller/Behavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'] ?? [];

Expand Down Expand Up @@ -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());
}

Expand Down
4 changes: 2 additions & 2 deletions src/Mvc/Controller/Rest/Actions/GetAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
use Phalcon\Http\ResponseInterface;
use Zemit\Mvc\Controller\AbstractTrait\AbstractInjectable;

trait GetAction {
trait GetAction
{
use AbstractInjectable;

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Mvc/Controller/Rest/Actions/GetListAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
use Phalcon\Http\ResponseInterface;
use Zemit\Mvc\Controller\AbstractTrait\AbstractInjectable;

trait GetListAction {
trait GetListAction
{
use AbstractInjectable;

/**
Expand All @@ -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,
Expand Down
12 changes: 4 additions & 8 deletions src/Mvc/Controller/Rest/Actions/IndexAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ trait IndexAction

/**
* @throws Exception
* @throws \Phalcon\Filter\Exception
*/
public function indexAction(): ResponseInterface
{
Expand All @@ -32,6 +33,7 @@ public function indexAction(): ResponseInterface

/**
* @throws Exception
* @throws \Phalcon\Filter\Exception
*/
protected function restForwarding(): bool
{
Expand All @@ -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;
}
Expand Down
8 changes: 6 additions & 2 deletions src/Mvc/Controller/Rest/Actions/NewAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 945df2c

Please sign in to comment.