From f48a5df9bbfa5e88f7fc7e7fc43d8ebe23b5f113 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20D?= Date: Sun, 26 Jun 2022 13:06:03 +0200 Subject: [PATCH] chore: Inject adapters. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rubén D --- .../api/Controllers/Category/CategoryBase.php | 6 +++++- .../api/Controllers/Category/ViewController.php | 4 +--- app/modules/api/Controllers/Client/ClientBase.php | 10 +++++++++- .../api/Controllers/Client/ViewController.php | 13 ++----------- .../Controllers/Account/AccountControllerBase.php | 4 +++- app/modules/web/Controllers/ControllerBase.php | 2 +- 6 files changed, 21 insertions(+), 18 deletions(-) diff --git a/app/modules/api/Controllers/Category/CategoryBase.php b/app/modules/api/Controllers/Category/CategoryBase.php index 68a8a766..af8e0e2e 100644 --- a/app/modules/api/Controllers/Category/CategoryBase.php +++ b/app/modules/api/Controllers/Category/CategoryBase.php @@ -30,6 +30,7 @@ use SP\Core\Acl\Acl; use SP\Core\Application; use SP\Domain\Api\ApiServiceInterface; use SP\Domain\Category\CategoryServiceInterface; +use SP\Domain\Category\Out\CategoryAdapterInterface; use SP\Modules\Api\Controllers\ControllerBase; use SP\Modules\Api\Controllers\Help\CategoryHelp; @@ -39,6 +40,7 @@ use SP\Modules\Api\Controllers\Help\CategoryHelp; abstract class CategoryBase extends ControllerBase { protected CategoryServiceInterface $categoryService; + protected CategoryAdapterInterface $categoryAdapter; /** * @throws \SP\Core\Exceptions\InvalidClassException @@ -48,11 +50,13 @@ abstract class CategoryBase extends ControllerBase Klein $router, ApiServiceInterface $apiService, Acl $acl, - CategoryServiceInterface $categoryService + CategoryServiceInterface $categoryService, + CategoryAdapterInterface $categoryAdapter ) { parent::__construct($application, $router, $apiService, $acl); $this->categoryService = $categoryService; + $this->categoryAdapter = $categoryAdapter; $this->apiService->setHelpClass(CategoryHelp::class); } diff --git a/app/modules/api/Controllers/Category/ViewController.php b/app/modules/api/Controllers/Category/ViewController.php index 612b225f..e0a04e47 100644 --- a/app/modules/api/Controllers/Category/ViewController.php +++ b/app/modules/api/Controllers/Category/ViewController.php @@ -30,7 +30,6 @@ use SP\Core\Acl\ActionsInterface; use SP\Core\Events\Event; use SP\Core\Events\EventMessage; use SP\Domain\Api\Services\ApiResponse; -use SP\Domain\Category\Out\CategoryAdapter; use SP\Util\Util; @@ -65,8 +64,7 @@ final class ViewController extends CategoryBase ) ); - $out = $this->fractal - ->createData(new Item($categoryData, new CategoryAdapter($this->configData))); + $out = $this->fractal->createData(new Item($categoryData, $this->categoryAdapter)); if ($customFields) { $this->apiService->requireMasterPass(); diff --git a/app/modules/api/Controllers/Client/ClientBase.php b/app/modules/api/Controllers/Client/ClientBase.php index 40296a7d..b5b8af95 100644 --- a/app/modules/api/Controllers/Client/ClientBase.php +++ b/app/modules/api/Controllers/Client/ClientBase.php @@ -30,6 +30,7 @@ use SP\Core\Acl\Acl; use SP\Core\Application; use SP\Domain\Api\ApiServiceInterface; use SP\Domain\Client\ClientServiceInterface; +use SP\Domain\Client\Out\ClientAdapterInterface; use SP\Modules\Api\Controllers\ControllerBase; use SP\Modules\Api\Controllers\Help\ClientHelp; @@ -39,18 +40,25 @@ use SP\Modules\Api\Controllers\Help\ClientHelp; abstract class ClientBase extends ControllerBase { protected ClientServiceInterface $clientService; + protected ClientAdapterInterface $clientAdapter; + /** + * @throws \SP\Core\Exceptions\InvalidClassException + */ public function __construct( Application $application, Klein $router, ApiServiceInterface $apiService, Acl $acl, - ClientServiceInterface $clientService + ClientServiceInterface $clientService, + ClientAdapterInterface $clientAdapter ) { parent::__construct($application, $router, $apiService, $acl); $this->clientService = $clientService; + $this->clientAdapter = $clientAdapter; $this->apiService->setHelpClass(ClientHelp::class); + } } \ No newline at end of file diff --git a/app/modules/api/Controllers/Client/ViewController.php b/app/modules/api/Controllers/Client/ViewController.php index 3a83b7a3..c12ef7a4 100644 --- a/app/modules/api/Controllers/Client/ViewController.php +++ b/app/modules/api/Controllers/Client/ViewController.php @@ -30,7 +30,6 @@ use SP\Core\Acl\ActionsInterface; use SP\Core\Events\Event; use SP\Core\Events\EventMessage; use SP\Domain\Api\Services\ApiResponse; -use SP\Domain\Client\Out\ClientAdapter; use SP\Util\Util; /** @@ -52,10 +51,7 @@ final class ViewController extends ClientBase $clientData = $this->clientService->getById($id); - $this->eventDispatcher->notifyEvent( - 'show.client', - new Event($this) - ); + $this->eventDispatcher->notifyEvent('show.client', new Event($this)); $this->eventDispatcher->notifyEvent( 'show.client', @@ -72,12 +68,7 @@ final class ViewController extends ClientBase $this->apiService->requireMasterPass(); } - $out = $this->fractal - ->createData( - new Item( - $clientData, - new ClientAdapter($this->configData) - )); + $out = $this->fractal->createData(new Item($clientData, $this->clientAdapter)); if ($customFields) { $this->apiService->requireMasterPass(); diff --git a/app/modules/web/Controllers/Account/AccountControllerBase.php b/app/modules/web/Controllers/Account/AccountControllerBase.php index 0e7c9f46..395abef4 100644 --- a/app/modules/web/Controllers/Account/AccountControllerBase.php +++ b/app/modules/web/Controllers/Account/AccountControllerBase.php @@ -38,9 +38,11 @@ abstract class AccountControllerBase extends ControllerBase private const LOGIN_NOT_REQUIRED = ['ViewLinkController']; /** + * @param \SP\Core\Application $application + * @param \SP\Mvc\Controller\WebControllerHelper $webControllerHelper + * * @throws \SP\Core\Exceptions\SessionTimeout * @throws \SP\Domain\Auth\Services\AuthException - * @throws \JsonException */ public function __construct(Application $application, WebControllerHelper $webControllerHelper) { diff --git a/app/modules/web/Controllers/ControllerBase.php b/app/modules/web/Controllers/ControllerBase.php index 386bbb26..48803550 100644 --- a/app/modules/web/Controllers/ControllerBase.php +++ b/app/modules/web/Controllers/ControllerBase.php @@ -129,7 +129,7 @@ abstract class ControllerBase $this->view->assign('ctx_userIsAdminAcc', $this->userData->getIsAdminAcc()); } - $this->view->assign('action', true); + $this->view->assign('action', $this->actionName); } /**