From 674c9154b71834095407ccf8da51283107a45b9b Mon Sep 17 00:00:00 2001 From: nuxsmin Date: Wed, 14 Feb 2018 00:24:35 +0100 Subject: [PATCH] * [MOD] Improved IoC handling. Work in progress --- .../Controllers/AccessManagerController.php | 47 +++-- .../web/Controllers/AccountController.php | 63 +++++-- .../web/Controllers/AccountFileController.php | 11 +- .../web/Controllers/ApiTokenController.php | 16 +- .../web/Controllers/CategoryController.php | 16 +- .../web/Controllers/ClientController.php | 15 +- .../Controllers/ConfigManagerController.php | 16 +- .../web/Controllers/CustomFieldController.php | 14 +- .../Helpers/Account/AccountHelper.php | 59 +++--- .../Helpers/Account/AccountHistoryHelper.php | 31 ++-- .../Helpers/Account/AccountPasswordHelper.php | 4 +- .../Helpers/Account/AccountSearchHelper.php | 20 +- .../web/Controllers/Helpers/HelperBase.php | 16 +- .../Controllers/Helpers/ItemsGridHelper.php | 14 +- .../web/Controllers/Helpers/LayoutHelper.php | 24 +-- .../web/Controllers/IndexController.php | 5 +- .../web/Controllers/InstallController.php | 5 +- .../web/Controllers/ItemManagerController.php | 71 +++++--- .../web/Controllers/ItemsController.php | 33 ++-- .../web/Controllers/LoginController.php | 13 +- .../web/Controllers/PassresetController.php | 4 +- .../web/Controllers/PublicLinkController.php | 16 +- .../web/Controllers/ResourceController.php | 8 +- .../web/Controllers/SimpleControllerBase.php | 82 ++++++--- app/modules/web/Controllers/TagController.php | 15 +- .../web/Controllers/UserController.php | 12 +- .../web/Controllers/UserGroupController.php | 18 +- .../web/Controllers/UserProfileController.php | 12 +- lib/SP/Account/AccountAcl.php | 1 - lib/SP/Controller/ControllerBase.php | 172 +++++++----------- lib/SP/Controller/RequestControllerTrait.php | 2 - lib/SP/Core/Dic/Injector.php | 18 +- lib/SP/Core/Install/Installer.php | 1 - lib/SP/Core/Language.php | 25 +-- lib/SP/Core/Session/Session.php | 26 ++- lib/SP/Html/Minify.php | 13 +- .../Account/AccountRepository.php | 18 +- lib/SP/Repositories/Repository.php | 30 ++- .../Services/Account/AccountFileService.php | 20 +- .../Account/AccountHistoryService.php | 47 ++--- .../Services/Account/AccountSearchService.php | 57 +++--- lib/SP/Services/Account/AccountService.php | 90 +++++---- lib/SP/Services/Auth/LoginService.php | 102 ++++------- .../Services/AuthToken/AuthTokenService.php | 30 +-- lib/SP/Services/Category/CategoryService.php | 18 +- lib/SP/Services/Client/ClientService.php | 24 +-- lib/SP/Services/Config/ConfigService.php | 21 +-- .../CustomField/CustomFieldDefService.php | 22 +-- .../Services/PublicLink/PublicLinkService.php | 46 ++--- lib/SP/Services/Service.php | 34 ++-- lib/SP/Services/ServiceItemTrait.php | 5 +- lib/SP/Services/Tag/TagService.php | 23 +-- lib/SP/Services/User/UserPassService.php | 30 +-- lib/SP/Services/User/UserService.php | 25 +-- .../Services/UserGroup/UserGroupService.php | 35 ++-- .../UserGroup/UserToUserGroupService.php | 24 +-- .../UserPassRecoverService.php | 21 +-- .../UserProfile/UserProfileService.php | 22 +-- 58 files changed, 781 insertions(+), 881 deletions(-) diff --git a/app/modules/web/Controllers/AccessManagerController.php b/app/modules/web/Controllers/AccessManagerController.php index 94af8cf8..800a3615 100644 --- a/app/modules/web/Controllers/AccessManagerController.php +++ b/app/modules/web/Controllers/AccessManagerController.php @@ -58,8 +58,10 @@ class AccessManagerController extends ControllerBase protected $tabsGridHelper; /** - * @throws \SP\Core\Exceptions\InvalidArgumentException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Dic\ContainerException + * @throws \SP\Core\Exceptions\InvalidArgumentException */ public function indexAction() { @@ -69,17 +71,18 @@ class AccessManagerController extends ControllerBase /** * Returns a tabbed grid with items * - * @throws \SP\Core\Exceptions\InvalidArgumentException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Dic\ContainerException + * @throws \SP\Core\Exceptions\InvalidArgumentException */ protected function getGridTabs() { $this->itemSearchData = new ItemSearchData(); $this->itemSearchData->setLimitCount($this->configData->getAccountCount()); - $this->itemsGridHelper = new ItemsGridHelper($this->view, $this->config, $this->session, $this->eventDispatcher); - - $this->tabsGridHelper = new TabsGridHelper($this->view, $this->config, $this->session, $this->eventDispatcher); + $this->itemsGridHelper = $this->dic->get(ItemsGridHelper::class); + $this->tabsGridHelper = $this->dic->get(TabsGridHelper::class); if ($this->checkAccess(ActionsInterface::USER)) { $this->tabsGridHelper->addTab($this->getUsersList()); @@ -111,61 +114,67 @@ class AccessManagerController extends ControllerBase /** * Returns users' data tab * + * @return \SP\Html\DataGrid\DataGridTab + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Dic\ContainerException */ protected function getUsersList() { - $service = new UserService(); - return $this->itemsGridHelper->getUsersGrid($service->search($this->itemSearchData))->updatePager(); + return $this->itemsGridHelper->getUsersGrid($this->dic->get(UserService::class)->search($this->itemSearchData))->updatePager(); } /** * Returns users group data tab * + * @return \SP\Html\DataGrid\DataGridTab + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Dic\ContainerException */ protected function getUsersGroupList() { - $service = new UserGroupService(); - - return $this->itemsGridHelper->getUserGroupsGrid($service->search($this->itemSearchData))->updatePager(); + return $this->itemsGridHelper->getUserGroupsGrid($this->dic->get(UserGroupService::class)->search($this->itemSearchData))->updatePager(); } /** * Returns users profile data tab * + * @return \SP\Html\DataGrid\DataGridTab + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Dic\ContainerException */ protected function getUsersProfileList() { - $service = new UserProfileService(); - - return $this->itemsGridHelper->getUserProfilesGrid($service->search($this->itemSearchData))->updatePager(); + return $this->itemsGridHelper->getUserProfilesGrid($this->dic->get(UserProfileService::class)->search($this->itemSearchData))->updatePager(); } /** * Returns API tokens data tab * + * @return \SP\Html\DataGrid\DataGridTab + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Dic\ContainerException */ protected function getApiTokensList() { - $service = new AuthTokenService(); - - return $this->itemsGridHelper->getApiTokensGrid($service->search($this->itemSearchData))->updatePager(); + return $this->itemsGridHelper->getApiTokensGrid($this->dic->get(AuthTokenService::class)->search($this->itemSearchData))->updatePager(); } /** * Returns public links data tab * + * @return \SP\Html\DataGrid\DataGridTab + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Dic\ContainerException */ protected function getPublicLinksList() { - $service = new PublicLinkService(); - - return $this->itemsGridHelper->getPublicLinksGrid($service->search($this->itemSearchData))->updatePager(); + return $this->itemsGridHelper->getPublicLinksGrid($this->dic->get(PublicLinkService::class)->search($this->itemSearchData))->updatePager(); } /** diff --git a/app/modules/web/Controllers/AccountController.php b/app/modules/web/Controllers/AccountController.php index d27cb054..d4eee7cb 100644 --- a/app/modules/web/Controllers/AccountController.php +++ b/app/modules/web/Controllers/AccountController.php @@ -71,7 +71,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac public function indexAction() { try { - $accountSearchHelper = new AccountSearchHelper($this->view, $this->config, $this->session, $this->eventDispatcher); + $accountSearchHelper = $this->dic->get(AccountSearchHelper::class); $accountSearchHelper->getSearchBox(); $accountSearchHelper->getAccountSearch(); @@ -93,7 +93,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac public function searchAction() { try { - $AccountSearchHelper = new AccountSearchHelper($this->view, $this->config, $this->session, $this->eventDispatcher); + $AccountSearchHelper = $this->dic->get(AccountSearchHelper::class); $AccountSearchHelper->getAccountSearch(); $this->eventDispatcher->notifyEvent('show.account.search', $this); @@ -115,6 +115,8 @@ class AccountController extends ControllerBase implements CrudControllerInterfac * View action * * @param int $id Account's ID + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ public function viewAction($id) { @@ -125,7 +127,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac ->withUserGroupsById($accountDetailsResponse) ->withTagsById($accountDetailsResponse); - $accountHelper = new AccountHelper($this->view, $this->config, $this->session, $this->eventDispatcher); + $accountHelper = $this->dic->get(AccountHelper::class); $accountHelper->setIsView(true); $accountHelper->setViewForAccount($accountDetailsResponse, ActionsInterface::ACCOUNT_VIEW); @@ -154,15 +156,17 @@ class AccountController extends ControllerBase implements CrudControllerInterfac * View public link action * * @param string $hash Link's hash + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Dic\ContainerException */ public function viewLinkAction($hash) { - $layoutHelper = new LayoutHelper($this->view, $this->config, $this->session, $this->eventDispatcher); - $layoutHelper->getPublicLayout(['name' => 'account-link', 'base' => 'account'], 'account'); + $layoutHelper = $this->dic->get(LayoutHelper::class); + $layoutHelper->getPublicLayout('account-link', 'account'); try { - $publicLinkService = new PublicLinkService(); + $publicLinkService = $this->dic->get(PublicLinkService::class); $publicLinkData = $publicLinkService->getByHash($hash); if (time() < $publicLinkData->getDateExpire() @@ -235,7 +239,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac public function createAction() { try { - $accountHelper = new AccountHelper($this->view, $this->config, $this->session, $this->eventDispatcher); + $accountHelper = $this->dic->get(AccountHelper::class); $accountHelper->setViewForBlank(ActionsInterface::ACCOUNT_CREATE); $this->view->addTemplate('account'); @@ -262,6 +266,8 @@ class AccountController extends ControllerBase implements CrudControllerInterfac * Copy action * * @param int $id Account's ID + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ public function copyAction($id) { @@ -272,7 +278,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac ->withUserGroupsById($accountDetailsResponse) ->withTagsById($accountDetailsResponse); - $accountHelper = new AccountHelper($this->view, $this->config, $this->session, $this->eventDispatcher); + $accountHelper = $this->dic->get(AccountHelper::class); $accountHelper->setViewForAccount($accountDetailsResponse, ActionsInterface::ACCOUNT_COPY); $this->view->addTemplate('account'); @@ -299,6 +305,8 @@ class AccountController extends ControllerBase implements CrudControllerInterfac * Edit action * * @param int $id Account's ID + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ public function editAction($id) { @@ -309,7 +317,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac ->withUserGroupsById($accountDetailsResponse) ->withTagsById($accountDetailsResponse); - $accountHelper = new AccountHelper($this->view, $this->config, $this->session, $this->eventDispatcher); + $accountHelper = $this->dic->get(AccountHelper::class); $accountHelper->setViewForAccount($accountDetailsResponse, ActionsInterface::ACCOUNT_EDIT); $this->view->addTemplate('account'); @@ -339,6 +347,8 @@ class AccountController extends ControllerBase implements CrudControllerInterfac * Delete action * * @param int $id Account's ID + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ public function deleteAction($id) { @@ -348,7 +358,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac ->withUsersById($accountDetailsResponse) ->withUserGroupsById($accountDetailsResponse); - $accountHelper = new AccountHelper($this->view, $this->config, $this->session, $this->eventDispatcher); + $accountHelper = $this->dic->get(AccountHelper::class); $accountHelper->setViewForAccount($accountDetailsResponse, ActionsInterface::ACCOUNT_DELETE); $this->view->addTemplate('account'); @@ -375,6 +385,8 @@ class AccountController extends ControllerBase implements CrudControllerInterfac * Obtener los datos para mostrar el interface para modificar la clave de cuenta * * @param int $id Account's ID + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ public function editPassAction($id) { @@ -384,7 +396,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac ->withUsersById($accountDetailsResponse) ->withUserGroupsById($accountDetailsResponse); - $accountHelper = new AccountHelper($this->view, $this->config, $this->session, $this->eventDispatcher); + $accountHelper = $this->dic->get(AccountHelper::class); $accountHelper->setViewForAccount($accountDetailsResponse, ActionsInterface::ACCOUNT_EDIT_PASS); $this->view->addTemplate('account-editpass'); @@ -413,14 +425,16 @@ class AccountController extends ControllerBase implements CrudControllerInterfac * Obtener los datos para mostrar el interface para ver cuenta en fecha concreta * * @param int $id Account's ID + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ public function viewHistoryAction($id) { try { - $accountHistoryService = new AccountHistoryService(); + $accountHistoryService = $this->dic->get(AccountHistoryService::class); $accountHistoryData = $accountHistoryService->getById($id); - $accountHistoryHelper = new AccountHistoryHelper($this->view, $this->config, $this->session, $this->eventDispatcher); + $accountHistoryHelper = $this->dic->get(AccountHistoryHelper::class); $accountHistoryHelper->setView($accountHistoryData, ActionsInterface::ACCOUNT_VIEW_HISTORY); $this->view->addTemplate('account-history'); @@ -449,11 +463,13 @@ class AccountController extends ControllerBase implements CrudControllerInterfac * Obtener los datos para mostrar el interface de solicitud de cambios en una cuenta * * @param int $id Account's ID + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ public function requestAccessAction($id) { try { - $accountHelper = new AccountHelper($this->view, $this->config, $this->session, $this->eventDispatcher); + $accountHelper = $this->dic->get(AccountHelper::class); $accountHelper->setIsView(true); $accountHelper->setViewForRequest($this->accountService->getById($id), ActionsInterface::ACCOUNT_REQUEST); @@ -480,7 +496,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac public function viewPassAction($id, $isHistory) { try { - $accountPassHelper = new AccountPasswordHelper($this->view, $this->config, $this->session, $this->eventDispatcher); + $accountPassHelper = $this->dic->get(AccountPasswordHelper::class); $account = $isHistory === 0 ? $this->accountService->getPasswordForId($id) : $this->accountService->getPasswordHistoryForId($id); @@ -509,12 +525,13 @@ class AccountController extends ControllerBase implements CrudControllerInterfac * @throws Helpers\HelperException * @throws SPException * @throws \Defuse\Crypto\Exception\CryptoException - * @throws \SP\Core\Dic\ContainerException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Exceptions\InvalidArgumentException */ public function copyPassAction($id, $isHistory) { - $accountPassHelper = new AccountPasswordHelper($this->view, $this->config, $this->session, $this->eventDispatcher); + $accountPassHelper = $this->dic->get(AccountPasswordHelper::class); $account = $isHistory === 0 ? $this->accountService->getPasswordForId($id) : $this->accountService->getPasswordHistoryForId($id); @@ -576,6 +593,8 @@ class AccountController extends ControllerBase implements CrudControllerInterfac * Saves edit action * * @param $id Account's ID + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Dic\ContainerException */ public function saveEditAction($id) @@ -611,6 +630,8 @@ class AccountController extends ControllerBase implements CrudControllerInterfac * Saves edit action * * @param $id Account's ID + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Dic\ContainerException */ public function saveEditPassAction($id) @@ -645,7 +666,8 @@ class AccountController extends ControllerBase implements CrudControllerInterfac * * @param int $historyId Account's history ID * @param int $id Account's ID - * @throws \SP\Core\Dic\ContainerException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ public function saveEditRestoreAction($historyId, $id) { @@ -698,7 +720,8 @@ class AccountController extends ControllerBase implements CrudControllerInterfac /** * Initialize class * - * @throws \SP\Core\Dic\ContainerException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ protected function initialize() { @@ -706,6 +729,6 @@ class AccountController extends ControllerBase implements CrudControllerInterfac $this->checkLoggedIn(); } - $this->accountService = new AccountService(); + $this->accountService = $this->dic->get(AccountService::class); } } \ No newline at end of file diff --git a/app/modules/web/Controllers/AccountFileController.php b/app/modules/web/Controllers/AccountFileController.php index d2d17723..83514dbe 100644 --- a/app/modules/web/Controllers/AccountFileController.php +++ b/app/modules/web/Controllers/AccountFileController.php @@ -197,6 +197,8 @@ class AccountFileController extends ControllerBase implements CrudControllerInte /** * Search action * + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Dic\ContainerException */ public function searchAction() @@ -205,7 +207,7 @@ class AccountFileController extends ControllerBase implements CrudControllerInte return; } - $itemsGridHelper = new ItemsGridHelper($this->view, $this->config, $this->session, $this->eventDispatcher); + $itemsGridHelper = $this->dic->get(ItemsGridHelper::class); $grid = $itemsGridHelper->getFilesGrid($this->accountFileService->search($this->getSearchData($this->configData)))->updatePager(); $this->view->addTemplate('datagrid-table', 'grid'); @@ -284,8 +286,6 @@ class AccountFileController extends ControllerBase implements CrudControllerInte } try { - $this->setAction(ActionsInterface::ACCOUNT_FILE); - $this->view->addTemplate('files-list', 'account'); $this->view->assign('deleteEnabled', Request::analyze('del', 0)); @@ -312,12 +312,13 @@ class AccountFileController extends ControllerBase implements CrudControllerInte /** * Initialize class * - * @throws \SP\Core\Dic\ContainerException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ protected function initialize() { $this->checkLoggedIn(); - $this->accountFileService = new AccountFileService(); + $this->accountFileService = $this->dic->get(AccountFileService::class); } } \ No newline at end of file diff --git a/app/modules/web/Controllers/ApiTokenController.php b/app/modules/web/Controllers/ApiTokenController.php index 1d88749a..b84575be 100644 --- a/app/modules/web/Controllers/ApiTokenController.php +++ b/app/modules/web/Controllers/ApiTokenController.php @@ -31,7 +31,6 @@ use SP\Core\Acl\Acl; use SP\Core\Acl\ActionsInterface; use SP\Core\Exceptions\SPException; use SP\Core\Exceptions\ValidationException; -use SP\Core\SessionUtil; use SP\DataModel\AuthTokenData; use SP\Forms\AuthTokenForm; use SP\Http\JsonResponse; @@ -63,6 +62,8 @@ class ApiTokenController extends ControllerBase implements CrudControllerInterfa /** * Search action * + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Dic\ContainerException */ public function searchAction() @@ -71,7 +72,7 @@ class ApiTokenController extends ControllerBase implements CrudControllerInterfa return; } - $itemsGridHelper = new ItemsGridHelper($this->view, $this->config, $this->session, $this->eventDispatcher); + $itemsGridHelper = $this->dic->get(ItemsGridHelper::class); $grid = $itemsGridHelper->getApiTokensGrid($this->authTokenService->search($this->getSearchData($this->configData)))->updatePager(); $this->view->addTemplate('datagrid-table', 'grid'); @@ -122,10 +123,10 @@ class ApiTokenController extends ControllerBase implements CrudControllerInterfa $this->view->assign('authToken', $authToken); - $this->view->assign('users', (new SelectItemAdapter(UserService::getItemsBasic()))->getItemsFromModelSelected([$authToken->getUserId()])); - $this->view->assign('actions', (new SelectItemAdapter(ApiTokensUtil::getTokenActions()))->getItemsFromArraySelected([$authToken->getActionId()])); + $this->view->assign('users', SelectItemAdapter::factory(UserService::getItemsBasic())->getItemsFromModelSelected([$authToken->getUserId()])); + $this->view->assign('actions', SelectItemAdapter::factory(ApiTokensUtil::getTokenActions())->getItemsFromArraySelected([$authToken->getActionId()])); - $this->view->assign('sk', SessionUtil::getSessionKey(true)); + $this->view->assign('sk', $this->session->generateSecurityKey()); $this->view->assign('nextAction', Acl::getActionRoute(ActionsInterface::ACCESS_MANAGE)); if ($this->view->isView === true) { @@ -304,12 +305,13 @@ class ApiTokenController extends ControllerBase implements CrudControllerInterfa /** * Initialize class * - * @throws \SP\Core\Dic\ContainerException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ protected function initialize() { $this->checkLoggedIn(); - $this->authTokenService = new AuthTokenService(); + $this->authTokenService = $this->dic->get(AuthTokenService::class); } } \ No newline at end of file diff --git a/app/modules/web/Controllers/CategoryController.php b/app/modules/web/Controllers/CategoryController.php index 843f2d27..37a180cd 100644 --- a/app/modules/web/Controllers/CategoryController.php +++ b/app/modules/web/Controllers/CategoryController.php @@ -29,7 +29,6 @@ use SP\Core\Acl\Acl; use SP\Core\Acl\ActionsInterface; use SP\Core\Exceptions\SPException; use SP\Core\Exceptions\ValidationException; -use SP\Core\SessionUtil; use SP\DataModel\CategoryData; use SP\Forms\CategoryForm; use SP\Http\JsonResponse; @@ -58,6 +57,8 @@ class CategoryController extends ControllerBase implements CrudControllerInterfa /** * Search action * + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Dic\ContainerException */ public function searchAction() @@ -66,7 +67,7 @@ class CategoryController extends ControllerBase implements CrudControllerInterfa return; } - $itemsGridHelper = new ItemsGridHelper($this->view, $this->config, $this->session, $this->eventDispatcher); + $itemsGridHelper = $this->dic->get(ItemsGridHelper::class); $grid = $itemsGridHelper->getCategoriesGrid($this->categoryService->search($this->getSearchData($this->configData)))->updatePager(); $this->view->addTemplate('datagrid-table', 'grid'); @@ -117,7 +118,7 @@ class CategoryController extends ControllerBase implements CrudControllerInterfa $this->view->assign('category', $category); - $this->view->assign('sk', SessionUtil::getSessionKey(true)); + $this->view->assign('sk', $this->session->generateSecurityKey()); $this->view->assign('nextAction', Acl::getActionRoute(ActionsInterface::ITEMS_MANAGE)); if ($this->view->isView === true) { @@ -162,6 +163,7 @@ class CategoryController extends ControllerBase implements CrudControllerInterfa * Delete action * * @param $id + * @throws \SP\Core\Dic\ContainerException */ public function deleteAction($id) { @@ -186,6 +188,8 @@ class CategoryController extends ControllerBase implements CrudControllerInterfa /** * Saves create action + * + * @throws \SP\Core\Dic\ContainerException */ public function saveCreateAction() { @@ -217,6 +221,7 @@ class CategoryController extends ControllerBase implements CrudControllerInterfa * Saves edit action * * @param $id + * @throws \SP\Core\Dic\ContainerException */ public function saveEditAction($id) { @@ -273,13 +278,14 @@ class CategoryController extends ControllerBase implements CrudControllerInterfa /** * Initialize class * - * @throws \SP\Core\Dic\ContainerException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ protected function initialize() { $this->checkLoggedIn(); - $this->categoryService = new CategoryService(); + $this->categoryService = $this->dic->get(CategoryService::class); } } \ No newline at end of file diff --git a/app/modules/web/Controllers/ClientController.php b/app/modules/web/Controllers/ClientController.php index c4927ef1..3e3f4972 100644 --- a/app/modules/web/Controllers/ClientController.php +++ b/app/modules/web/Controllers/ClientController.php @@ -30,7 +30,6 @@ use SP\Core\Acl\Acl; use SP\Core\Acl\ActionsInterface; use SP\Core\Exceptions\SPException; use SP\Core\Exceptions\ValidationException; -use SP\Core\SessionUtil; use SP\DataModel\ClientData; use SP\Forms\ClientForm; use SP\Http\JsonResponse; @@ -59,6 +58,8 @@ class ClientController extends ControllerBase implements CrudControllerInterface /** * Search action * + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Dic\ContainerException */ public function searchAction() @@ -67,7 +68,7 @@ class ClientController extends ControllerBase implements CrudControllerInterface return; } - $itemsGridHelper = new ItemsGridHelper($this->view, $this->config, $this->session, $this->eventDispatcher); + $itemsGridHelper = $this->dic->get(ItemsGridHelper::class); $grid = $itemsGridHelper->getClientsGrid($this->clientService->search($this->getSearchData($this->configData)))->updatePager(); $this->view->addTemplate('datagrid-table', 'grid'); @@ -118,7 +119,7 @@ class ClientController extends ControllerBase implements CrudControllerInterface $this->view->assign('client', $client); - $this->view->assign('sk', SessionUtil::getSessionKey(true)); + $this->view->assign('sk', $this->session->generateSecurityKey()); $this->view->assign('nextAction', Acl::getActionRoute(ActionsInterface::ITEMS_MANAGE)); if ($this->view->isView === true) { @@ -187,6 +188,8 @@ class ClientController extends ControllerBase implements CrudControllerInterface /** * Saves create action + * + * @throws \SP\Core\Dic\ContainerException */ public function saveCreateAction() { @@ -216,6 +219,7 @@ class ClientController extends ControllerBase implements CrudControllerInterface * Saves edit action * * @param $id + * @throws \SP\Core\Dic\ContainerException */ public function saveEditAction($id) { @@ -270,13 +274,14 @@ class ClientController extends ControllerBase implements CrudControllerInterface /** * Initialize class * - * @throws \SP\Core\Dic\ContainerException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ protected function initialize() { $this->checkLoggedIn(); - $this->clientService = new ClientService(); + $this->clientService = $this->dic->get(ClientService::class); } } \ No newline at end of file diff --git a/app/modules/web/Controllers/ConfigManagerController.php b/app/modules/web/Controllers/ConfigManagerController.php index 9caca3a7..203a52e2 100644 --- a/app/modules/web/Controllers/ConfigManagerController.php +++ b/app/modules/web/Controllers/ConfigManagerController.php @@ -50,8 +50,9 @@ class ConfigManagerController extends ControllerBase protected $tabsHelper; /** + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Exceptions\InvalidArgumentException - * @throws \SP\Core\Dic\ContainerException */ public function indexAction() { @@ -61,12 +62,13 @@ class ConfigManagerController extends ControllerBase /** * Returns a tabbed grid with items * + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Exceptions\InvalidArgumentException - * @throws \SP\Core\Dic\ContainerException */ protected function getTabs() { - $this->tabsHelper = new TabsHelper($this->view, $this->config, $this->session, $this->eventDispatcher); + $this->tabsHelper = $this->dic->get(TabsHelper::class); if ($this->checkAccess(ActionsInterface::CONFIG_GENERAL)) { $this->tabsHelper->addTab($this->getConfigGeneral()); @@ -110,6 +112,8 @@ class ConfigManagerController extends ControllerBase /** * @return DataTab + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ protected function getConfigGeneral() { @@ -170,6 +174,8 @@ class ConfigManagerController extends ControllerBase /** * @return DataTab + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ protected function getLdapConfig() { @@ -187,6 +193,8 @@ class ConfigManagerController extends ControllerBase /** * @return DataTab + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ protected function getMailConfig() { @@ -204,6 +212,8 @@ class ConfigManagerController extends ControllerBase /** * @return DataTab + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ protected function getEncryptionConfig() { diff --git a/app/modules/web/Controllers/CustomFieldController.php b/app/modules/web/Controllers/CustomFieldController.php index 0490aa47..76a072d6 100644 --- a/app/modules/web/Controllers/CustomFieldController.php +++ b/app/modules/web/Controllers/CustomFieldController.php @@ -30,7 +30,6 @@ use SP\Core\Acl\Acl; use SP\Core\Acl\ActionsInterface; use SP\Core\Exceptions\SPException; use SP\Core\Exceptions\ValidationException; -use SP\Core\SessionUtil; use SP\DataModel\CustomFieldDefinitionData; use SP\Forms\CustomFieldDefForm; use SP\Http\JsonResponse; @@ -61,6 +60,8 @@ class CustomFieldController extends ControllerBase implements CrudControllerInte /** * Search action * + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Dic\ContainerException */ public function searchAction() @@ -69,7 +70,7 @@ class CustomFieldController extends ControllerBase implements CrudControllerInte return; } - $itemsGridHelper = new ItemsGridHelper($this->view, $this->config, $this->session, $this->eventDispatcher); + $itemsGridHelper = $this->dic->get(ItemsGridHelper::class); $grid = $itemsGridHelper->getCustomFieldsGrid($this->customFieldService->search($this->getSearchData($this->configData)))->updatePager(); $this->view->addTemplate('datagrid-table', 'grid'); @@ -118,13 +119,14 @@ class CustomFieldController extends ControllerBase implements CrudControllerInte $customField = $customFieldId ? $this->customFieldService->getById($customFieldId) : new CustomFieldDefinitionData(); + // FIXME $customFieldTypeService = new CustomFieldTypeRepository(); $this->view->assign('field', $customField); $this->view->assign('types', $customFieldTypeService->getAll()); $this->view->assign('modules', CustomFieldDefRepository::getFieldModules()); - $this->view->assign('sk', SessionUtil::getSessionKey(true)); + $this->view->assign('sk', $this->session->generateSecurityKey()); $this->view->assign('nextAction', Acl::getActionRoute(ActionsInterface::ITEMS_MANAGE)); if ($this->view->isView === true) { @@ -220,6 +222,7 @@ class CustomFieldController extends ControllerBase implements CrudControllerInte * Saves edit action * * @param $id + * @throws \SP\Core\Dic\ContainerException */ public function saveEditAction($id) { @@ -274,13 +277,14 @@ class CustomFieldController extends ControllerBase implements CrudControllerInte /** * Initialize class * - * @throws \SP\Core\Dic\ContainerException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ protected function initialize() { $this->checkLoggedIn(); - $this->customFieldService = new CustomFieldDefService(); + $this->customFieldService = $this->dic->get(CustomFieldDefService::class); } } \ No newline at end of file diff --git a/app/modules/web/Controllers/Helpers/Account/AccountHelper.php b/app/modules/web/Controllers/Helpers/Account/AccountHelper.php index 427e9487..13be14b3 100644 --- a/app/modules/web/Controllers/Helpers/Account/AccountHelper.php +++ b/app/modules/web/Controllers/Helpers/Account/AccountHelper.php @@ -25,6 +25,7 @@ namespace SP\Modules\Web\Controllers\Helpers\Account; use SP\Account\AccountAcl; +use SP\Bootstrap; use SP\Core\Acl\AccountPermissionException; use SP\Core\Acl\Acl; use SP\Core\Acl\ActionsInterface; @@ -88,35 +89,19 @@ class AccountHelper extends HelperBase */ private $isView = false; - /** - * @param Acl $acl - * @param AccountService $accountService - * @param AccountHistoryService $accountHistoryService - * @param PublicLinkService $publicLinkService - */ - public function inject(Acl $acl, - AccountService $accountService, - AccountHistoryService $accountHistoryService, - PublicLinkService $publicLinkService - ) - { - $this->acl = $acl; - $this->accountService = $accountService; - $this->accountHistoryService = $accountHistoryService; - $this->publicLinkService = $publicLinkService; - } - /** * Sets account's view variables * * @param AccountDetailsResponse $accountDetailsResponse * @param int $actionId - * @throws UnauthorizedPageException - * @throws UpdatedMasterPassException - * @throws \SP\Core\Dic\ContainerException * @throws AccountPermissionException * @throws SPException + * @throws UnauthorizedPageException + * @throws UpdatedMasterPassException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \ReflectionException + * @throws \SP\Core\Dic\ContainerException */ public function setViewForAccount(AccountDetailsResponse $accountDetailsResponse, $actionId) { @@ -162,7 +147,7 @@ class AccountHelper extends HelperBase $this->view->assign('accountData', $accountData); $this->view->assign('gotData', true); - $this->view->assign('actions', $this->getActionsHelper()->getActionsForAccount($accountAcl, new AccountActionsDto($this->accountId, null, $accountData->getParentId()))); + $this->view->assign('actions', Bootstrap::getContainer()->get(AccountActionsHelper::class)->getActionsForAccount($accountAcl, new AccountActionsDto($this->accountId, null, $accountData->getParentId()))); $this->setViewCommon(); } @@ -210,17 +195,11 @@ class AccountHelper extends HelperBase return $accountAcl; } - /** - * @return AccountActionsHelper - * @throws \SP\Core\Dic\ContainerException - */ - protected function getActionsHelper() - { - return new AccountActionsHelper($this->view, $this->config, $this->session, $this->eventDispatcher); - } - /** * Sets account's view common data + * + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ protected function setViewCommon() { @@ -265,6 +244,9 @@ class AccountHelper extends HelperBase * @return void * @throws UnauthorizedPageException * @throws UpdatedMasterPassException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface + * @throws \ReflectionException * @throws \SP\Core\Dic\ContainerException */ public function setViewForBlank($actionId) @@ -287,7 +269,7 @@ class AccountHelper extends HelperBase $this->view->assign('accountId', 0); $this->view->assign('gotData', false); - $this->view->assign('actions', $this->getActionsHelper()->getActionsForAccount($this->accountAcl, new AccountActionsDto($this->accountId))); + $this->view->assign('actions', Bootstrap::getContainer()->get(AccountActionsHelper::class)->getActionsForAccount($this->accountAcl, new AccountActionsDto($this->accountId))); $this->setViewCommon(); } @@ -300,6 +282,9 @@ class AccountHelper extends HelperBase * @return bool * @throws UnauthorizedPageException * @throws UpdatedMasterPassException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface + * @throws \ReflectionException * @throws \SP\Core\Dic\ContainerException */ public function setViewForRequest(AccountDetailsResponse $accountDetailsResponse, $actionId) @@ -315,7 +300,7 @@ class AccountHelper extends HelperBase $this->view->assign('accountId', $accountData->getId()); $this->view->assign('accountData', $accountDetailsResponse->getAccountVData()); - $this->view->assign('actions', $this->getActionsHelper()->getActionsForAccount($this->accountAcl->getStoredAcl(), new AccountActionsDto($this->accountId, null, $accountData->getParentId()))); + $this->view->assign('actions', Bootstrap::getContainer()->get(AccountActionsHelper::class)->getActionsForAccount($this->accountAcl->getStoredAcl(), new AccountActionsDto($this->accountId, null, $accountData->getParentId()))); return true; } @@ -329,10 +314,16 @@ class AccountHelper extends HelperBase } /** - * Initialize class + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ protected function initialize() { + $this->acl = $this->dic->get(Acl::class); + $this->accountService = $this->dic->get(AccountService::class);; + $this->accountHistoryService = $this->dic->get(AccountHistoryService::class);; + $this->publicLinkService = $this->dic->get(PublicLinkService::class);; + $this->view->assign('changesHash'); $this->view->assign('chkUserEdit'); $this->view->assign('chkGroupEdit'); diff --git a/app/modules/web/Controllers/Helpers/Account/AccountHistoryHelper.php b/app/modules/web/Controllers/Helpers/Account/AccountHistoryHelper.php index eaddd582..d7c6b82b 100644 --- a/app/modules/web/Controllers/Helpers/Account/AccountHistoryHelper.php +++ b/app/modules/web/Controllers/Helpers/Account/AccountHistoryHelper.php @@ -25,7 +25,9 @@ namespace SP\Modules\Web\Controllers\Helpers\Account; use SP\Account\AccountAcl; +use SP\Core\Acl\AccountPermissionException; use SP\Core\Acl\Acl; +use SP\Core\Exceptions\SPException; use SP\DataModel\AccountHistoryData; use SP\DataModel\Dto\AccountAclDto; use SP\Mgmt\Users\UserPass; @@ -68,22 +70,14 @@ class AccountHistoryHelper extends HelperBase */ protected $accountAcl; - - /** - * @param Acl $acl - * @param AccountHistoryService $accountHistoryService - */ - public function inject(Acl $acl, AccountHistoryService $accountHistoryService) - { - $this->acl = $acl; - $this->accountHistoryService = $accountHistoryService; - } - /** * @param AccountHistoryData $accountHistoryData * @param int $actionId - * @return bool + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface + * @throws \ReflectionException * @throws \SP\Core\Dic\ContainerException + * @throws AccountPermissionException */ public function setView(AccountHistoryData $accountHistoryData, $actionId) { @@ -93,8 +87,7 @@ class AccountHistoryHelper extends HelperBase $this->accountAcl = new AccountAcl($actionId, true); if (!$this->checkActionAccess() || !$this->checkAccess($accountHistoryData)) { - // FIXME: throw exception - return false; + throw new AccountPermissionException(SPException::INFO); } $this->view->assign('isView', true); @@ -111,11 +104,9 @@ class AccountHistoryHelper extends HelperBase $this->view->assign('clients', SelectItemAdapter::factory(ClientService::getItemsBasic())->getItemsFromModelSelected([$accountHistoryData->getClientId()])); $this->view->assign('isModified', strtotime($accountHistoryData->getDateEdit()) !== false); - $actions = new AccountActionsHelper($this->view, $this->config, $this->session, $this->eventDispatcher); + $actions = $this->dic->get(AccountActionsHelper::class); $this->view->assign('actions', $actions->getActionsForAccount($this->accountAcl->getStoredAcl(), new AccountActionsDto($this->accountId, $this->accountHistoryId))); - - return true; } /** @@ -165,9 +156,15 @@ class AccountHistoryHelper extends HelperBase /** * Initialize class + * + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ protected function initialize() { + $this->acl = $this->dic->get(Acl::class); + $this->accountHistoryService = $this->dic->get(AccountHistoryService::class);; + $this->view->assign('sk', $this->session->generateSecurityKey()); } } \ No newline at end of file diff --git a/app/modules/web/Controllers/Helpers/Account/AccountPasswordHelper.php b/app/modules/web/Controllers/Helpers/Account/AccountPasswordHelper.php index 72385143..e7028d2d 100644 --- a/app/modules/web/Controllers/Helpers/Account/AccountPasswordHelper.php +++ b/app/modules/web/Controllers/Helpers/Account/AccountPasswordHelper.php @@ -28,7 +28,6 @@ use SP\Core\Acl\Acl; use SP\Core\Acl\ActionsInterface; use SP\Core\Crypt\Crypt; use SP\Core\Crypt\Session as CryptSession; -use SP\Core\SessionUtil; use SP\DataModel\AccountPassData; use SP\Mgmt\Users\UserPass; use SP\Modules\Web\Controllers\Helpers\HelperBase; @@ -87,6 +86,7 @@ class AccountPasswordHelper extends HelperBase throw new HelperException(__u('No tiene permisos para acceder a esta cuenta')); } + // FIXME if (!UserPass::checkUserUpdateMPass($this->session->getUserData()->getId())) { throw new HelperException(__('Clave maestra actualizada') . '
' . __('Reinicie la sesión para cambiarla')); } @@ -121,6 +121,6 @@ class AccountPasswordHelper extends HelperBase } $this->view->assign('isLinked', $accountData->getParentId() > 0); - $this->view->assign('sk', SessionUtil::getSessionKey(true)); + $this->view->assign('sk', $this->session->generateSecurityKey()); } } \ No newline at end of file diff --git a/app/modules/web/Controllers/Helpers/Account/AccountSearchHelper.php b/app/modules/web/Controllers/Helpers/Account/AccountSearchHelper.php index 4a6a6929..96856466 100644 --- a/app/modules/web/Controllers/Helpers/Account/AccountSearchHelper.php +++ b/app/modules/web/Controllers/Helpers/Account/AccountSearchHelper.php @@ -27,7 +27,6 @@ namespace SP\Modules\Web\Controllers\Helpers\Account; use SP\Account\AccountSearchFilter; use SP\Account\AccountSearchItem; use SP\Core\Acl\ActionsInterface; -use SP\Core\SessionUtil; use SP\Html\DataGrid\DataGrid; use SP\Html\DataGrid\DataGridAction; use SP\Html\DataGrid\DataGridActionSearch; @@ -72,15 +71,16 @@ class AccountSearchHelper extends HelperBase /** * Obtener los datos para la caja de búsqueda * - * @throws \SP\Core\Dic\ContainerException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ public function getSearchBox() { $this->view->addTemplate('search-searchbox'); - $this->view->assign('clients', (new SelectItemAdapter((new ClientService())->getAllForUser()))->getItemsFromModelSelected([$this->accountSearchFilter->getClientId()])); - $this->view->assign('categories', (new SelectItemAdapter(CategoryService::getItemsBasic()))->getItemsFromModelSelected([$this->accountSearchFilter->getCategoryId()])); - $this->view->assign('tags', (new SelectItemAdapter(TagService::getItemsBasic()))->getItemsFromModelSelected($this->accountSearchFilter->getTagsId())); + $this->view->assign('clients', SelectItemAdapter::factory($this->dic->get(ClientService::class)->getAllForUser())->getItemsFromModelSelected([$this->accountSearchFilter->getClientId()])); + $this->view->assign('categories', SelectItemAdapter::factory(CategoryService::getItemsBasic())->getItemsFromModelSelected([$this->accountSearchFilter->getCategoryId()])); + $this->view->assign('tags', SelectItemAdapter::factory(TagService::getItemsBasic())->getItemsFromModelSelected($this->accountSearchFilter->getTagsId())); } /** @@ -88,6 +88,7 @@ class AccountSearchHelper extends HelperBase * * @throws \Psr\Container\ContainerExceptionInterface * @throws \SP\Core\Exceptions\SPException + * @throws \ReflectionException */ public function getAccountSearch() { @@ -121,7 +122,7 @@ class AccountSearchHelper extends HelperBase $this->view->assign('wikiPageUrl', $this->configData->getWikiPageurl()); } - $accountSearchService = new AccountSearchService(); + $accountSearchService = $this->dic->get(AccountSearchService::class); $Grid = $this->getGrid(); $Grid->getData()->setData($accountSearchService->processSearchResults($this->accountSearchFilter)); @@ -139,7 +140,8 @@ class AccountSearchHelper extends HelperBase * Devuelve la matriz a utilizar en la vista * * @return DataGrid - * @throws \Psr\Container\ContainerExceptionInterface + * @throws \ReflectionException + * @throws \SP\Core\Dic\ContainerException */ private function getGrid() { @@ -169,7 +171,7 @@ class AccountSearchHelper extends HelperBase $userPreferences = $this->session->getUserData()->getPreferences(); $showOptionalActions = $userPreferences->isOptionalActions() || $userPreferences->isResultsAsCards() || ($userPreferences->getUserId() === 0 && $this->configData->isResultsAsCards()); - $actions = new AccountActionsHelper($this->view, $this->config, $this->session, $this->eventDispatcher); + $actions = $this->dic->get(AccountActionsHelper::class); $Grid = new DataGrid(); $Grid->setId('gridSearch'); @@ -252,7 +254,7 @@ class AccountSearchHelper extends HelperBase protected function initialize() { $this->queryTimeStart = microtime(); - $this->sk = SessionUtil::getSessionKey(true); + $this->sk = $this->session->generateSecurityKey(); $this->view->assign('sk', $this->sk); $this->setVars(); } diff --git a/app/modules/web/Controllers/Helpers/HelperBase.php b/app/modules/web/Controllers/Helpers/HelperBase.php index 5968058e..08af1762 100644 --- a/app/modules/web/Controllers/Helpers/HelperBase.php +++ b/app/modules/web/Controllers/Helpers/HelperBase.php @@ -24,11 +24,12 @@ namespace SP\Modules\Web\Controllers\Helpers; +use DI\Container; +use Psr\Container\ContainerInterface; use SP\Config\Config; use SP\Config\ConfigData; use SP\Core\Events\EventDispatcher; use SP\Core\Session\Session; -use SP\Core\Traits\InjectableTrait; use SP\Mvc\View\Template; /** @@ -38,8 +39,6 @@ use SP\Mvc\View\Template; */ abstract class HelperBase { - use InjectableTrait; - /** * @var \SP\Mvc\View\Template */ @@ -60,6 +59,10 @@ abstract class HelperBase * @var Config */ protected $config; + /** + * @var ContainerInterface + */ + protected $dic; /** * Constructor @@ -68,12 +71,11 @@ abstract class HelperBase * @param Config $config * @param Session $session * @param EventDispatcher $eventDispatcher - * @throws \SP\Core\Dic\ContainerException + * @param Container $container */ - final public function __construct(Template $template, Config $config, Session $session, EventDispatcher $eventDispatcher) + final public function __construct(Template $template, Config $config, Session $session, EventDispatcher $eventDispatcher, Container $container) { - $this->injectDependencies(); - + $this->dic = $container; $this->view = $template; $this->config = $config; $this->configData = $config->getConfigData(); diff --git a/app/modules/web/Controllers/Helpers/ItemsGridHelper.php b/app/modules/web/Controllers/Helpers/ItemsGridHelper.php index a48301ea..e273aff5 100644 --- a/app/modules/web/Controllers/Helpers/ItemsGridHelper.php +++ b/app/modules/web/Controllers/Helpers/ItemsGridHelper.php @@ -26,6 +26,7 @@ namespace SP\Modules\Web\Controllers\Helpers; defined('APP_ROOT') || die(); +use SP\Bootstrap; use SP\Core\Acl\Acl; use SP\Core\Acl\ActionsInterface; use SP\Core\UI\ThemeIconsBase; @@ -56,14 +57,6 @@ class ItemsGridHelper extends HelperBase */ protected $acl; - /** - * @param \SP\Core\Acl\Acl $acl - */ - public function inject(Acl $acl) - { - $this->acl = $acl; - } - /** * @param array $data * @return DataGridTab @@ -1223,8 +1216,13 @@ class ItemsGridHelper extends HelperBase return $Grid; } + /** + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface + */ protected function initialize() { + $this->acl = Bootstrap::getContainer()->get(Acl::class); $this->icons = $this->view->getTheme()->getIcons(); } } \ No newline at end of file diff --git a/app/modules/web/Controllers/Helpers/LayoutHelper.php b/app/modules/web/Controllers/Helpers/LayoutHelper.php index af812459..4dacbcbd 100644 --- a/app/modules/web/Controllers/Helpers/LayoutHelper.php +++ b/app/modules/web/Controllers/Helpers/LayoutHelper.php @@ -46,18 +46,14 @@ use SP\Util\Util; */ class LayoutHelper extends HelperBase { - /** @var bool */ - protected $loggedIn; - /** @var ThemeInterface */ - protected $theme; - /** - * @param Theme $theme + * @var bool */ - public function inject(Theme $theme) - { - $this->theme = $theme; - } + protected $loggedIn; + /** + * @var ThemeInterface + */ + protected $theme; /** * Sets a full layout page @@ -106,7 +102,7 @@ class LayoutHelper extends HelperBase $this->view->assign('startTime', microtime()); $this->view->assign('isInstalled', $this->configData->isInstalled()); - $this->view->assign('sk', SessionUtil::getSessionKey(true, $this->configData)); + $this->view->assign('sk', $this->session->generateSecurityKey()); $this->view->assign('appInfo', Util::getAppInfo()); $this->view->assign('appVersion', Util::getVersionString()); $this->view->assign('isDemoMode', $this->configData->isDemoEnabled()); @@ -368,8 +364,14 @@ class LayoutHelper extends HelperBase return $this; } + /** + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface + */ protected function initialize() { + $this->theme = Bootstrap::getContainer()->get(Theme::class); + $this->loggedIn = $this->session->isLoggedIn(); $this->view->assign('loggedIn', $this->loggedIn); diff --git a/app/modules/web/Controllers/IndexController.php b/app/modules/web/Controllers/IndexController.php index e6eb057c..c53cf13d 100644 --- a/app/modules/web/Controllers/IndexController.php +++ b/app/modules/web/Controllers/IndexController.php @@ -39,15 +39,16 @@ class IndexController extends ControllerBase /** * Index action * + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Dic\ContainerException - * @throws \ReflectionException */ public function indexAction() { if (!$this->session->isLoggedIn()) { Response::redirect('index.php?r=login'); } else { - $LayoutHelper = new LayoutHelper($this->view, $this->config, $this->session, $this->eventDispatcher); + $LayoutHelper = $this->dic->get(LayoutHelper::class); $LayoutHelper->getFullLayout('main', $this->acl); $this->view(); diff --git a/app/modules/web/Controllers/InstallController.php b/app/modules/web/Controllers/InstallController.php index 0c874dfa..8ce039ad 100644 --- a/app/modules/web/Controllers/InstallController.php +++ b/app/modules/web/Controllers/InstallController.php @@ -46,12 +46,13 @@ class InstallController extends ControllerBase use JsonTrait; /** + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface * @throws \SP\Core\Dic\ContainerException - * @throws \ReflectionException */ public function indexAction() { - $layoutHelper = new LayoutHelper($this->view, $this->config, $this->session, $this->eventDispatcher); + $layoutHelper = $this->dic->get(LayoutHelper::class); $layoutHelper->getPublicLayout('index', 'install'); $errors = []; diff --git a/app/modules/web/Controllers/ItemManagerController.php b/app/modules/web/Controllers/ItemManagerController.php index 56ae3d85..de44304e 100644 --- a/app/modules/web/Controllers/ItemManagerController.php +++ b/app/modules/web/Controllers/ItemManagerController.php @@ -61,8 +61,10 @@ class ItemManagerController extends ControllerBase protected $tabsGridHelper; /** - * @throws \SP\Core\Exceptions\InvalidArgumentException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Dic\ContainerException + * @throws \SP\Core\Exceptions\InvalidArgumentException */ public function indexAction() { @@ -72,17 +74,18 @@ class ItemManagerController extends ControllerBase /** * Returns a tabbed grid with items * - * @throws \SP\Core\Exceptions\InvalidArgumentException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Dic\ContainerException + * @throws \SP\Core\Exceptions\InvalidArgumentException */ protected function getGridTabs() { $this->itemSearchData = new ItemSearchData(); $this->itemSearchData->setLimitCount($this->configData->getAccountCount()); - $this->itemsGridHelper = new ItemsGridHelper($this->view, $this->config, $this->session, $this->eventDispatcher); - - $this->tabsGridHelper = new TabsGridHelper($this->view, $this->config, $this->session, $this->eventDispatcher); + $this->itemsGridHelper = $this->dic->get(ItemsGridHelper::class); + $this->tabsGridHelper = $this->dic->get(TabsGridHelper::class); if ($this->checkAccess(ActionsInterface::CATEGORY)) { $this->tabsGridHelper->addTab($this->getCategoriesList()); @@ -126,96 +129,106 @@ class ItemManagerController extends ControllerBase /** * Returns categories' data tab * + * @return \SP\Html\DataGrid\DataGridTab + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Dic\ContainerException */ protected function getCategoriesList() { - $service = new CategoryService(); - - return $this->itemsGridHelper->getCategoriesGrid($service->search($this->itemSearchData))->updatePager(); + return $this->itemsGridHelper->getCategoriesGrid($this->dic->get(CategoryService::class)->search($this->itemSearchData))->updatePager(); } /** * Returns tags' data tab * + * @return \SP\Html\DataGrid\DataGridTab + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Dic\ContainerException */ protected function getTagsList() { - $service = new TagService(); - - return $this->itemsGridHelper->getTagsGrid($service->search($this->itemSearchData))->updatePager(); + return $this->itemsGridHelper->getTagsGrid($this->dic->get(TagService::class)->search($this->itemSearchData))->updatePager(); } /** * Returns clients' data tab * + * @return \SP\Html\DataGrid\DataGridTab + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Dic\ContainerException */ protected function getClientsList() { - $service = new ClientService(); - - return $this->itemsGridHelper->getClientsGrid($service->search($this->itemSearchData))->updatePager(); + return $this->itemsGridHelper->getClientsGrid($this->dic->get(ClientService::class)->search($this->itemSearchData))->updatePager(); } /** * Returns custom fields' data tab * + * @return \SP\Html\DataGrid\DataGridTab + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Dic\ContainerException */ protected function getCustomFieldsList() { - $service = new CustomFieldDefService(); - - return $this->itemsGridHelper->getCustomFieldsGrid($service->search($this->itemSearchData))->updatePager(); + return $this->itemsGridHelper->getCustomFieldsGrid($this->dic->get(CustomFieldDefService::class)->search($this->itemSearchData))->updatePager(); } /** * Returns account files' data tab * + * @return \SP\Html\DataGrid\DataGridTab + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Dic\ContainerException */ protected function getAccountFilesList() { - $service = new AccountFileService(); - - return $this->itemsGridHelper->getFilesGrid($service->search($this->itemSearchData))->updatePager(); + return $this->itemsGridHelper->getFilesGrid($this->dic->get(AccountFileService::class)->search($this->itemSearchData))->updatePager(); } /** * Returns accounts' data tab * + * @return \SP\Html\DataGrid\DataGridTab + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Dic\ContainerException */ protected function getAccountsList() { - $service = new AccountService(); - - return $this->itemsGridHelper->getAccountsGrid($service->search($this->itemSearchData))->updatePager(); + return $this->itemsGridHelper->getAccountsGrid($this->dic->get(AccountService::class)->search($this->itemSearchData))->updatePager(); } /** * Returns accounts' history data tab * + * @return \SP\Html\DataGrid\DataGridTab + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Dic\ContainerException */ protected function getAccountsHistoryList() { - $service = new AccountHistoryService(); - - return $this->itemsGridHelper->getAccountsHistoryGrid($service->search($this->itemSearchData))->updatePager(); + return $this->itemsGridHelper->getAccountsHistoryGrid($this->dic->get(AccountHistoryService::class)->search($this->itemSearchData))->updatePager(); } /** * Returns plugins' data tab + * + * @return \SP\Html\DataGrid\DataGridTab + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface + * @throws \SP\Core\Dic\ContainerException */ protected function getPluginsList() { // FIXME: create Plugin Service - $service = new PluginRepository(); - - return $this->itemsGridHelper->getPluginsGrid($service->search($this->itemSearchData))->updatePager(); + return $this->itemsGridHelper->getPluginsGrid($this->dic->get(PluginRepository::class)->search($this->itemSearchData))->updatePager(); } /** diff --git a/app/modules/web/Controllers/ItemsController.php b/app/modules/web/Controllers/ItemsController.php index f57aa36f..bfa0d73e 100644 --- a/app/modules/web/Controllers/ItemsController.php +++ b/app/modules/web/Controllers/ItemsController.php @@ -24,9 +24,9 @@ namespace SP\Modules\Web\Controllers; -use SP\Controller\RequestControllerTrait; use SP\Core\SessionUtil; use SP\DataModel\DataModelInterface; +use SP\Http\JsonResponse; use SP\Mvc\View\Components\SelectItemAdapter; use SP\Services\Account\AccountService; use SP\Services\Category\CategoryService; @@ -38,16 +38,14 @@ use SP\Util\Json; * * @package SP\Modules\Web\Controllers */ -class ItemsController +class ItemsController extends SimpleControllerBase { - use RequestControllerTrait; - /** * ItemsController constructor. */ - public function __construct() + protected function initialize() { - $this->init(); + $this->checks(); } /** @@ -60,9 +58,7 @@ class ItemsController { $outItems = []; - $accountService = new AccountService(); - - foreach ($accountService->getForUser($accountId) as $account) { + foreach ($this->dic->get(AccountService::class)->getForUser($accountId) as $account) { $obj = new \stdClass(); $obj->id = $account->id; $obj->name = $account->clientName . ' - ' . $account->name; @@ -70,29 +66,32 @@ class ItemsController $outItems[] = $obj; } - $this->JsonResponse->setStatus(0); - $this->JsonResponse->setData($outItems); - $this->JsonResponse->setCsrf(SessionUtil::getSessionKey()); + $jsonResponse = new JsonResponse(); + $jsonResponse->setStatus(0); + $jsonResponse->setData($outItems); + $jsonResponse->setCsrf(SessionUtil::getSessionKey()); - Json::returnJson($this->JsonResponse); + Json::returnJson($jsonResponse); } /** - * @throws \SP\Core\Dic\ContainerException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Exceptions\SPException */ public function clientsAction() { - Json::returnRawJson((new SelectItemAdapter((new ClientService())->getAllForUser()))->getJsonItemsFromModel()); + Json::returnRawJson(SelectItemAdapter::factory($this->dic->get(ClientService::class)->getAllForUser())->getJsonItemsFromModel()); } /** - * @throws \SP\Core\Dic\ContainerException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Exceptions\SPException */ public function categoriesAction() { - Json::returnRawJson((new SelectItemAdapter((new CategoryService())->getAllBasic()))->getJsonItemsFromModel()); + Json::returnRawJson(SelectItemAdapter::factory($this->dic->get(CategoryService::class)->getAllBasic())->getJsonItemsFromModel()); } /** diff --git a/app/modules/web/Controllers/LoginController.php b/app/modules/web/Controllers/LoginController.php index cb3d128b..bd877fce 100644 --- a/app/modules/web/Controllers/LoginController.php +++ b/app/modules/web/Controllers/LoginController.php @@ -46,19 +46,19 @@ class LoginController extends ControllerBase * @throws \Defuse\Crypto\Exception\EnvironmentIsBrokenException * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface - * @throws \ReflectionException */ public function loginAction() { - $loginService = new LoginService($this->config, $this->session, $this->theme, $this->eventDispatcher); + $loginService = $this->dic->get(LoginService::class); Json::returnJson($loginService->doLogin()); } /** * Logout action * + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Dic\ContainerException - * @throws \ReflectionException */ public function logoutAction() { @@ -77,7 +77,7 @@ class LoginController extends ControllerBase SessionUtil::cleanSession(); SessionFactory::setLoggedOut(true); - $layoutHelper = new LayoutHelper($this->view, $this->config, $this->session, $this->eventDispatcher); + $layoutHelper = $this->dic->get(LayoutHelper::class); $layoutHelper->getCustomLayout('logout', 'logout'); $this->view(); @@ -89,12 +89,13 @@ class LoginController extends ControllerBase /** * Index action * + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Dic\ContainerException - * @throws \ReflectionException */ public function indexAction() { - $layoutHelper = new LayoutHelper($this->view, $this->config, $this->session, $this->eventDispatcher); + $layoutHelper = $this->dic->get(LayoutHelper::class); $layoutHelper->getCustomLayout('index', 'login'); if (SessionFactory::getLoggedOut() === true) { diff --git a/app/modules/web/Controllers/PassresetController.php b/app/modules/web/Controllers/PassresetController.php index 57671c0b..f0e4196d 100644 --- a/app/modules/web/Controllers/PassresetController.php +++ b/app/modules/web/Controllers/PassresetController.php @@ -39,11 +39,13 @@ class PassresetController extends ControllerBase /** * Password reset action * + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Dic\ContainerException */ public function indexAction() { - $LayoutHelper = new LayoutHelper($this->view, $this->config, $this->session, $this->eventDispatcher); + $LayoutHelper = $this->dic->get(LayoutHelper::class); $LayoutHelper->getPublicLayout('passreset', 'passreset'); if ($this->configData->isMailEnabled() || Request::analyze('f', 0) === 1) { diff --git a/app/modules/web/Controllers/PublicLinkController.php b/app/modules/web/Controllers/PublicLinkController.php index 3ad0ada3..bfa3733a 100644 --- a/app/modules/web/Controllers/PublicLinkController.php +++ b/app/modules/web/Controllers/PublicLinkController.php @@ -30,7 +30,6 @@ use SP\Core\Acl\Acl; use SP\Core\Acl\ActionsInterface; use SP\Core\Exceptions\SPException; use SP\Core\Exceptions\ValidationException; -use SP\Core\SessionUtil; use SP\DataModel\PublicLinkListData; use SP\Forms\PublicLinkForm; use SP\Http\JsonResponse; @@ -61,6 +60,8 @@ class PublicLinkController extends ControllerBase implements CrudControllerInter /** * Search action * + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Dic\ContainerException */ public function searchAction() @@ -69,7 +70,7 @@ class PublicLinkController extends ControllerBase implements CrudControllerInter return; } - $itemsGridHelper = new ItemsGridHelper($this->view, $this->config, $this->session, $this->eventDispatcher); + $itemsGridHelper = $this->dic->get(ItemsGridHelper::class); $grid = $itemsGridHelper->getPublicLinksGrid($this->publicLinkService->search($this->getSearchData($this->configData)))->updatePager(); $this->view->addTemplate('datagrid-table', 'grid'); @@ -121,9 +122,9 @@ class PublicLinkController extends ControllerBase implements CrudControllerInter $this->view->assign('publicLink', $publicLink); $this->view->assign('usageInfo', unserialize($publicLink->getUseInfo())); - $this->view->assign('accounts', (new SelectItemAdapter((new AccountService())->getForUser()))->getItemsFromModelSelected([$publicLink->getItemId()])); + $this->view->assign('accounts', SelectItemAdapter::factory($this->dic->get(AccountService::class)->getForUser())->getItemsFromModelSelected([$publicLink->getItemId()])); - $this->view->assign('sk', SessionUtil::getSessionKey(true)); + $this->view->assign('sk', $this->session->generateSecurityKey()); $this->view->assign('nextAction', Acl::getActionRoute(ActionsInterface::ACCESS_MANAGE)); if ($this->view->isView === true) { @@ -221,6 +222,8 @@ class PublicLinkController extends ControllerBase implements CrudControllerInter /** * Saves create action * + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Dic\ContainerException */ public function saveCreateAction() @@ -291,12 +294,13 @@ class PublicLinkController extends ControllerBase implements CrudControllerInter /** * Initialize class * - * @throws \SP\Core\Dic\ContainerException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ protected function initialize() { $this->checkLoggedIn(); - $this->publicLinkService = new PublicLinkService(); + $this->publicLinkService = $this->dic->get(PublicLinkService::class); } } \ No newline at end of file diff --git a/app/modules/web/Controllers/ResourceController.php b/app/modules/web/Controllers/ResourceController.php index a4efc2c2..aeb1cda0 100644 --- a/app/modules/web/Controllers/ResourceController.php +++ b/app/modules/web/Controllers/ResourceController.php @@ -42,15 +42,13 @@ class ResourceController extends SimpleControllerBase /** * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface - * @throws \ReflectionException - * @throws \SP\Core\Dic\ContainerException */ public function cssAction() { $file = Request::analyze('f'); $base = Request::analyze('b'); - $minify = new Minify(); + $minify = $this->dic->get(Minify::class); if ($file && $base) { $minify->setType(Minify::FILETYPE_CSS) @@ -76,15 +74,13 @@ class ResourceController extends SimpleControllerBase /** * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface - * @throws \ReflectionException - * @throws \SP\Core\Dic\ContainerException */ public function jsAction() { $file = Request::analyze('f'); $base = Request::analyze('b'); - $minify = new Minify(); + $minify = $this->dic->get(Minify::class); if ($file && $base) { $minify->setType(Minify::FILETYPE_JS) diff --git a/app/modules/web/Controllers/SimpleControllerBase.php b/app/modules/web/Controllers/SimpleControllerBase.php index 776586d8..73509a99 100644 --- a/app/modules/web/Controllers/SimpleControllerBase.php +++ b/app/modules/web/Controllers/SimpleControllerBase.php @@ -24,12 +24,18 @@ namespace SP\Modules\Web\Controllers; +use Interop\Container\ContainerInterface; use Klein\Klein; +use SP\Bootstrap; use SP\Config\Config; use SP\Core\Events\EventDispatcher; use SP\Core\Session\Session; -use SP\Core\Traits\InjectableTrait; use SP\Core\UI\Theme; +use SP\Http\JsonResponse; +use SP\Http\Request; +use SP\Util\Checks; +use SP\Util\Json; +use SP\Util\Util; /** * Class SimpleControllerBase @@ -38,12 +44,6 @@ use SP\Core\UI\Theme; */ abstract class SimpleControllerBase { - use InjectableTrait; - - /** - * @var int Módulo a usar - */ - protected $action; /** * @var string Nombre del controlador */ @@ -72,40 +72,80 @@ abstract class SimpleControllerBase * @var Klein */ protected $router; + /** + * @var ContainerInterface + */ + protected $dic; /** * SimpleControllerBase constructor. * * @param $actionName - * @throws \ReflectionException - * @throws \SP\Core\Dic\ContainerException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ public function __construct($actionName) { - $this->injectDependencies(); + $this->dic = Bootstrap::getContainer(); $class = static::class; $this->controllerName = substr($class, strrpos($class, '\\') + 1, -strlen('Controller')); $this->actionName = $actionName; + $this->config = $this->dic->get(Config::class); + $this->session = $this->dic->get(Session::class); + $this->theme = $this->dic->get(Theme::class); + $this->eventDispatcher = $this->dic->get(EventDispatcher::class); + $this->router = $this->dic->get(Klein::class); + if (method_exists($this, 'initialize')) { $this->initialize(); } } /** - * @param Config $config - * @param Session $session - * @param Theme $theme - * @param EventDispatcher $ev - * @param Klein $router + * Comprobar si la sesión está activa */ - public function inject(Config $config, Session $session, Theme $theme, EventDispatcher $ev, Klein $router) + protected function checkSession() { - $this->config = $config; - $this->session = $session; - $this->theme = $theme; - $this->eventDispatcher = $ev; - $this->router = $router; + if (!$this->session->isLoggedIn()) { + if (Checks::isJson()) { + $JsonResponse = new JsonResponse(); + $JsonResponse->setDescription(__u('La sesión no se ha iniciado o ha caducado')); + $JsonResponse->setStatus(10); + Json::returnJson($JsonResponse); + } else { + Util::logout(); + } + } + } + + /** + * Comprobaciones + */ + protected function checks() + { + $this->checkSession(); + $this->preActionChecks(); + } + + /** + * Comprobaciones antes de realizar una acción + */ + protected function preActionChecks() + { + $sk = Request::analyze('sk'); + + if (!$sk || (null !== $this->session->getSecurityKey() && $this->session->getSecurityKey() === $sk)) { + $this->invalidAction(); + } + } + + /** + * Acción no disponible + */ + protected function invalidAction() + { + Json::returnJson((new JsonResponse())->setDescription(__u('Acción Inválida'))); } } \ No newline at end of file diff --git a/app/modules/web/Controllers/TagController.php b/app/modules/web/Controllers/TagController.php index 6af7dfae..94338138 100644 --- a/app/modules/web/Controllers/TagController.php +++ b/app/modules/web/Controllers/TagController.php @@ -30,7 +30,6 @@ use SP\Core\Acl\Acl; use SP\Core\Acl\ActionsInterface; use SP\Core\Exceptions\SPException; use SP\Core\Exceptions\ValidationException; -use SP\Core\SessionUtil; use SP\DataModel\TagData; use SP\Forms\TagForm; use SP\Http\JsonResponse; @@ -59,6 +58,8 @@ class TagController extends ControllerBase implements CrudControllerInterface /** * Search action * + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Dic\ContainerException */ public function searchAction() @@ -67,7 +68,7 @@ class TagController extends ControllerBase implements CrudControllerInterface return; } - $itemsGridHelper = new ItemsGridHelper($this->view, $this->config, $this->session, $this->eventDispatcher); + $itemsGridHelper = $this->dic->get(ItemsGridHelper::class); $grid = $itemsGridHelper->getTagsGrid($this->tagService->search($this->getSearchData($this->configData)))->updatePager(); $this->view->addTemplate('datagrid-table', 'grid'); @@ -118,7 +119,7 @@ class TagController extends ControllerBase implements CrudControllerInterface $this->view->assign('tag', $tag); - $this->view->assign('sk', SessionUtil::getSessionKey(true)); + $this->view->assign('sk', $this->session->generateSecurityKey()); $this->view->assign('nextAction', Acl::getActionRoute(ActionsInterface::ITEMS_MANAGE)); if ($this->view->isView === true) { @@ -185,6 +186,8 @@ class TagController extends ControllerBase implements CrudControllerInterface /** * Saves create action + * + * @throws \SP\Core\Dic\ContainerException */ public function saveCreateAction() { @@ -214,6 +217,7 @@ class TagController extends ControllerBase implements CrudControllerInterface * Saves edit action * * @param $id + * @throws \SP\Core\Dic\ContainerException */ public function saveEditAction($id) { @@ -268,13 +272,14 @@ class TagController extends ControllerBase implements CrudControllerInterface /** * Initialize class * - * @throws \SP\Core\Dic\ContainerException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ protected function initialize() { $this->checkLoggedIn(); - $this->tagService = new TagService(); + $this->tagService = $this->dic->get(TagService::class); } } \ No newline at end of file diff --git a/app/modules/web/Controllers/UserController.php b/app/modules/web/Controllers/UserController.php index dddf4136..a7f1d495 100644 --- a/app/modules/web/Controllers/UserController.php +++ b/app/modules/web/Controllers/UserController.php @@ -62,6 +62,8 @@ class UserController extends ControllerBase implements CrudControllerInterface /** * Search action * + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Dic\ContainerException */ public function searchAction() @@ -70,7 +72,7 @@ class UserController extends ControllerBase implements CrudControllerInterface return; } - $itemsGridHelper = new ItemsGridHelper($this->view, $this->config, $this->session, $this->eventDispatcher); + $itemsGridHelper = $this->dic->get(ItemsGridHelper::class); $grid = $itemsGridHelper->getUsersGrid($this->userService->search($this->getSearchData($this->configData)))->updatePager(); $this->view->addTemplate('datagrid-table', 'grid'); @@ -121,10 +123,10 @@ class UserController extends ControllerBase implements CrudControllerInterface $user = $userId ? $this->userService->getById($userId) : new UserData(); $this->view->assign('user', $user); - $this->view->assign('groups', (new SelectItemAdapter(UserGroupService::getItemsBasic()))->getItemsFromModel()); - $this->view->assign('profiles', (new SelectItemAdapter(UserProfileService::getItemsBasic()))->getItemsFromModel()); + $this->view->assign('groups', SelectItemAdapter::factory(UserGroupService::getItemsBasic())->getItemsFromModel()); + $this->view->assign('profiles', SelectItemAdapter::factory(UserProfileService::getItemsBasic())->getItemsFromModel()); $this->view->assign('isUseSSO', $this->configData->isAuthBasicAutoLoginEnabled()); - $this->view->assign('sk', SessionUtil::getSessionKey(true)); + $this->view->assign('sk', $this->session->generateSecurityKey()); $this->view->assign('nextAction', Acl::getActionRoute(ActionsInterface::ACCESS_MANAGE)); if ($this->view->isView === true || $user->getLogin() === 'demo') { @@ -376,6 +378,6 @@ class UserController extends ControllerBase implements CrudControllerInterface { $this->checkLoggedIn(); - $this->userService = new UserService(); + $this->userService = $this->dic->get(UserService::class); } } \ No newline at end of file diff --git a/app/modules/web/Controllers/UserGroupController.php b/app/modules/web/Controllers/UserGroupController.php index 5e170db8..df306b6c 100644 --- a/app/modules/web/Controllers/UserGroupController.php +++ b/app/modules/web/Controllers/UserGroupController.php @@ -29,7 +29,6 @@ use SP\Core\Acl\Acl; use SP\Core\Acl\ActionsInterface; use SP\Core\Exceptions\SPException; use SP\Core\Exceptions\ValidationException; -use SP\Core\SessionUtil; use SP\DataModel\UserGroupData; use SP\Forms\UserGroupForm; use SP\Http\JsonResponse; @@ -65,6 +64,8 @@ class UserGroupController extends ControllerBase implements CrudControllerInterf /** * Search action * + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Dic\ContainerException */ public function searchAction() @@ -73,7 +74,7 @@ class UserGroupController extends ControllerBase implements CrudControllerInterf return; } - $itemsGridHelper = new ItemsGridHelper($this->view, $this->config, $this->session, $this->eventDispatcher); + $itemsGridHelper = $this->dic->get(ItemsGridHelper::class); $grid = $itemsGridHelper->getUserGroupsGrid($this->userGroupService->search($this->getSearchData($this->configData)))->updatePager(); $this->view->addTemplate('datagrid-table', 'grid'); @@ -114,6 +115,8 @@ class UserGroupController extends ControllerBase implements CrudControllerInterf * Sets view data for displaying user's data * * @param $userGroupId + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ protected function setViewData($userGroupId = null) { @@ -122,9 +125,9 @@ class UserGroupController extends ControllerBase implements CrudControllerInterf $group = $userGroupId ? $this->userGroupService->getById($userGroupId) : new UserGroupData(); $this->view->assign('group', $group); - $this->view->assign('users', (new SelectItemAdapter(UserService::getItemsBasic()))->getItemsFromModelSelected($this->userToUserGroupService->getUsersByGroupId($userGroupId))); + $this->view->assign('users', SelectItemAdapter::factory(UserService::getItemsBasic())->getItemsFromModelSelected($this->userToUserGroupService->getUsersByGroupId($userGroupId))); - $this->view->assign('sk', SessionUtil::getSessionKey(true)); + $this->view->assign('sk', $this->session->generateSecurityKey()); $this->view->assign('nextAction', Acl::getActionRoute(ActionsInterface::ACCESS_MANAGE)); if ($this->view->isView === true) { @@ -289,13 +292,14 @@ class UserGroupController extends ControllerBase implements CrudControllerInterf /** * Initialize class * - * @throws \SP\Core\Dic\ContainerException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ protected function initialize() { $this->checkLoggedIn(); - $this->userGroupService = new UserGroupService(); - $this->userToUserGroupService = new UserToUserGroupService(); + $this->userGroupService = $this->dic->get(UserGroupService::class); + $this->userToUserGroupService = $this->dic->get(UserToUserGroupService::class); } } \ No newline at end of file diff --git a/app/modules/web/Controllers/UserProfileController.php b/app/modules/web/Controllers/UserProfileController.php index 46b86410..ce795a33 100644 --- a/app/modules/web/Controllers/UserProfileController.php +++ b/app/modules/web/Controllers/UserProfileController.php @@ -29,7 +29,6 @@ use SP\Core\Acl\Acl; use SP\Core\Acl\ActionsInterface; use SP\Core\Exceptions\SPException; use SP\Core\Exceptions\ValidationException; -use SP\Core\SessionUtil; use SP\DataModel\ProfileData; use SP\Forms\UserProfileForm; use SP\Http\JsonResponse; @@ -58,6 +57,8 @@ class UserProfileController extends ControllerBase implements CrudControllerInte /** * Search action * + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Dic\ContainerException */ public function searchAction() @@ -66,7 +67,7 @@ class UserProfileController extends ControllerBase implements CrudControllerInte return; } - $itemsGridHelper = new ItemsGridHelper($this->view, $this->config, $this->session, $this->eventDispatcher); + $itemsGridHelper = $this->dic->get(ItemsGridHelper::class); $grid = $itemsGridHelper->getUserProfilesGrid($this->userProfileService->search($this->getSearchData($this->configData)))->updatePager(); $this->view->addTemplate('datagrid-table', 'grid'); @@ -117,7 +118,7 @@ class UserProfileController extends ControllerBase implements CrudControllerInte $this->view->assign('profile', $profile); - $this->view->assign('sk', SessionUtil::getSessionKey(true)); + $this->view->assign('sk', $this->session->generateSecurityKey()); $this->view->assign('nextAction', Acl::getActionRoute(ActionsInterface::ACCESS_MANAGE)); if ($this->view->isView === true) { @@ -282,12 +283,13 @@ class UserProfileController extends ControllerBase implements CrudControllerInte /** * Initialize class * - * @throws \SP\Core\Dic\ContainerException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ protected function initialize() { $this->checkLoggedIn(); - $this->userProfileService = new UserProfileService(); + $this->userProfileService = $this->dic->get(UserProfileService::class); } } \ No newline at end of file diff --git a/lib/SP/Account/AccountAcl.php b/lib/SP/Account/AccountAcl.php index 39111478..6e04289a 100644 --- a/lib/SP/Account/AccountAcl.php +++ b/lib/SP/Account/AccountAcl.php @@ -166,7 +166,6 @@ class AccountAcl * @param int $action * @param bool $isHistory * @throws \SP\Core\Dic\ContainerException - * @throws \ReflectionException */ public function __construct($action, $isHistory = false) { diff --git a/lib/SP/Controller/ControllerBase.php b/lib/SP/Controller/ControllerBase.php index ea237c6b..953f736b 100644 --- a/lib/SP/Controller/ControllerBase.php +++ b/lib/SP/Controller/ControllerBase.php @@ -27,13 +27,14 @@ namespace SP\Controller; defined('APP_ROOT') || die(); use Klein\Klein; +use Psr\Container\ContainerInterface; +use SP\Bootstrap; use SP\Config\Config; use SP\Config\ConfigData; use SP\Core\Acl\Acl; use SP\Core\Events\EventDispatcher; use SP\Core\Exceptions\FileNotFoundException; use SP\Core\Session\Session; -use SP\Core\Traits\InjectableTrait; use SP\Core\UI\Theme; use SP\Core\UI\ThemeIconsBase; use SP\DataModel\ProfileData; @@ -59,56 +60,95 @@ abstract class ControllerBase const ERR_OPERATION_NO_PERMISSION = 4; const ERR_EXCEPTION = 5; - - /** @var Template Instancia del motor de plantillas a utilizar */ + /** + * @var Template Instancia del motor de plantillas a utilizar + */ protected $view; - /** @var int ID de la acción */ + /** + * @var int ID de la acción + */ protected $action; - /** @var string Nombre de la acción */ + /** + * @var string Nombre de la acción + */ protected $actionName; - /** @var ThemeIconsBase Instancia de los iconos del tema visual */ + /** + * @var ThemeIconsBase Instancia de los iconos del tema visual + */ protected $icons; - /** @var string Nombre del controlador */ + /** + * @var string Nombre del controlador + */ protected $controllerName; - /** @var JsonResponse */ - protected $jsonResponse; - /** @var UserLoginResponse */ + /** + * @var UserLoginResponse + */ protected $userData; - /** @var ProfileData */ + /** + * @var ProfileData + */ protected $userProfileData; - /** @var EventDispatcher */ + /** + * @var EventDispatcher + */ protected $eventDispatcher; - /** @var bool */ + /** + * @var bool + */ protected $loggedIn = false; - /** @var ConfigData */ + /** + * @var ConfigData + */ protected $configData; - /** @var Config */ + /** + * @var Config + */ protected $config; - /** @var Session */ + /** + * @var Session + */ protected $session; - /** @var Theme */ + /** + * @var Theme + */ protected $theme; - /** @var \SP\Core\Acl\Acl */ + /** + * @var \SP\Core\Acl\Acl + */ protected $acl; - /** @var Klein */ + /** + * @var Klein + */ protected $router; - - use InjectableTrait; + /** + * @var ContainerInterface + */ + protected $dic; /** * Constructor * * @param $actionName - * @throws \SP\Core\Dic\ContainerException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ public function __construct($actionName) { - $this->injectDependencies(); + $this->dic = Bootstrap::getContainer(); $class = static::class; $this->controllerName = substr($class, strrpos($class, '\\') + 1, -strlen('Controller')); $this->actionName = $actionName; + $this->config = $this->dic->get(Config::class); + $this->configData = $this->config->getConfigData(); + $this->session = $this->dic->get(Session::class); + $this->theme = $this->dic->get(Theme::class); + $this->eventDispatcher = $this->dic->get(EventDispatcher::class); + $this->acl = $this->dic->get(Acl::class); + $this->router = $this->dic->get(Klein::class); + $this->view = $this->dic->get(Template::class); + $this->view->setBase(strtolower($this->controllerName)); $this->icons = $this->theme->getIcons(); @@ -140,45 +180,6 @@ abstract class ControllerBase $this->view->assign('isDemo', $this->configData->isDemoEnabled()); } - /** - * @param Config $config - * @param Session $session - * @param Theme $theme - * @param EventDispatcher $ev - * @param Acl $acl - * @param Klein $router - * @param Template $view - */ - public function inject(Config $config, Session $session, Theme $theme, EventDispatcher $ev, Acl $acl, Klein $router, Template $view) - { - $this->config = $config; - $this->configData = $config->getConfigData(); - $this->session = $session; - $this->theme = $theme; - $this->eventDispatcher = $ev; - $this->acl = $acl; - $this->router = $router; - $this->view = $view; - } - - /** - * @return int El id de la acción - */ - public function getAction() - { - return $this->action; - } - - /** - * Establecer el módulo a presentar. - * - * @param int $action El id de la acción - */ - public function setAction($action) - { - $this->action = (int)$action; - } - /** * Mostrar los datos de la plantilla */ @@ -205,7 +206,7 @@ abstract class ControllerBase } catch (FileNotFoundException $e) { debugLog($e->getMessage(), true); - echo $e->getMessage(); + return $e->getMessage(); } } @@ -223,29 +224,6 @@ abstract class ControllerBase $this->view->assign('memEnd', memory_get_usage() / 1000); } - /** - * Establecer la plantilla de error con el código indicado. - * - * @param int $type int con el tipo de error - * @param bool $reset - * @param null $replace - * @deprecated Use ErrorUtil class - */ - public function showError($type, $reset = true, $replace = null) - { - - } - - /** - * Realizar las acciones del controlador - * - * @param mixed $type Tipo de acción - */ - public function doAction($type = null) - { - - } - /** * Comprobar si el usuario está logado. */ @@ -254,7 +232,7 @@ abstract class ControllerBase if (!$this->session->isLoggedIn()) { if (Checks::isJson()) { $jsonResponse = new JsonResponse(); - $jsonResponse->setDescription(__('La sesión no se ha iniciado o ha caducado', false)); + $jsonResponse->setDescription(__u('La sesión no se ha iniciado o ha caducado')); $jsonResponse->setStatus(10); Json::returnJson($jsonResponse); @@ -273,30 +251,14 @@ abstract class ControllerBase $this->view->assign('loggedIn', $this->loggedIn); } - /** - * Establecer la instancia del motor de plantillas a utilizar. - * - * @param Template $template - */ - protected function setTemplate(Template $template) - { - $this->view = $template; - } - /** * Comprobar si está permitido el acceso al módulo/página. * * @param null $action La acción a comprobar * @return bool */ - protected function checkAccess($action = null) + protected function checkAccess($action) { - $checkAction = $this->action; - - if (null !== $action) { - $checkAction = $action; - } - - return $this->session->getUserData()->getIsAdminApp() || $this->acl->checkUserAccess($checkAction); + return $this->session->getUserData()->getIsAdminApp() || $this->acl->checkUserAccess($action); } } \ No newline at end of file diff --git a/lib/SP/Controller/RequestControllerTrait.php b/lib/SP/Controller/RequestControllerTrait.php index c276d172..bb79efd6 100644 --- a/lib/SP/Controller/RequestControllerTrait.php +++ b/lib/SP/Controller/RequestControllerTrait.php @@ -94,8 +94,6 @@ trait RequestControllerTrait */ protected function init() { - $this->injectDependencies(); - $this->JsonResponse = new JsonResponse(); $this->checkSession(); diff --git a/lib/SP/Core/Dic/Injector.php b/lib/SP/Core/Dic/Injector.php index a7d7bf10..13730de9 100644 --- a/lib/SP/Core/Dic/Injector.php +++ b/lib/SP/Core/Dic/Injector.php @@ -26,7 +26,6 @@ namespace SP\Core\Dic; use Interop\Container\ContainerInterface; use Psr\Container\ContainerExceptionInterface; -use Psr\Container\NotFoundExceptionInterface; use ReflectionMethod; /** @@ -48,31 +47,26 @@ class Injector { try { $reflectionMethod = new ReflectionMethod($context, 'inject'); - $methodParams = $reflectionMethod->getParameters(); - $params = []; - - if (!count($methodParams)) { + if ($reflectionMethod->getNumberOfParameters() === 0) { return false; } - foreach ($methodParams as $key => $methodParam) { - if ($methodParam->getClass()) { - $className = $methodParam->getClass()->getName(); + $params = []; - $params[$key] = $container->get($className); + foreach ($reflectionMethod->getParameters() as $key => $methodParam) { + if ($methodParam->getClass()) { + $params[$key] = $container->get($methodParam->getClass()->getName()); } else { $params[$key] = null; } } return $reflectionMethod->invokeArgs($context, $params); - } catch (NotFoundExceptionInterface $e) { + } catch (\Exception $e) { throw new ContainerException($e->getMessage(), $e->getCode(), $e); } catch (ContainerExceptionInterface $e) { throw new ContainerException($e->getMessage(), $e->getCode(), $e); - } catch (\ReflectionException $e) { - throw new ContainerException($e->getMessage(), $e->getCode(), $e); } } } \ No newline at end of file diff --git a/lib/SP/Core/Install/Installer.php b/lib/SP/Core/Install/Installer.php index 949a01d4..842c4781 100644 --- a/lib/SP/Core/Install/Installer.php +++ b/lib/SP/Core/Install/Installer.php @@ -100,7 +100,6 @@ class Installer * * @param InstallData $installData * @throws Dic\ContainerException - * @throws \ReflectionException */ public function __construct(InstallData $installData) { diff --git a/lib/SP/Core/Language.php b/lib/SP/Core/Language.php index 6ca75ee3..dfd3b667 100644 --- a/lib/SP/Core/Language.php +++ b/lib/SP/Core/Language.php @@ -27,7 +27,6 @@ namespace SP\Core; use SP\Config\Config; use SP\Config\ConfigData; use SP\Core\Session\Session; -use SP\Core\Traits\InjectableTrait; use SP\Http\Request; defined('APP_ROOT') || die(); @@ -39,8 +38,6 @@ defined('APP_ROOT') || die(); */ class Language { - use InjectableTrait; - /** * Lenguaje del usuario * @@ -69,15 +66,21 @@ class Language * @var ConfigData */ protected $configData; - /** @var Session */ + /** + * @var Session + */ protected $session; /** * Language constructor. + * + * @param Session $session + * @param Config $config */ - public function __construct() + public function __construct(Session $session, Config $config) { - $this->injectDependencies(); + $this->session = $session; + $this->configData = $config->getConfigData(); } /** @@ -105,16 +108,6 @@ class Language return $langs; } - /** - * @param Session $session - * @param Config $config - */ - public function inject(Session $session, Config $config) - { - $this->session = $session; - $this->configData = $config->getConfigData(); - } - /** * Establecer el lenguaje a utilizar * diff --git a/lib/SP/Core/Session/Session.php b/lib/SP/Core/Session/Session.php index 4d4aa5db..1d013155 100644 --- a/lib/SP/Core/Session/Session.php +++ b/lib/SP/Core/Session/Session.php @@ -51,7 +51,7 @@ class Session * Devolver una variable de sesión * * @param string $key - * @param mixed $default + * @param mixed $default * @return mixed */ protected function getSessionKey($key, $default = null) @@ -76,8 +76,8 @@ class Session /** * Establecer una variable de sesión * - * @param string $key El nombre de la variable - * @param mixed $value El valor de la variable + * @param string $key El nombre de la variable + * @param mixed $value El valor de la variable * @return mixed */ protected function setSessionKey($key, $value) @@ -409,4 +409,24 @@ class Session { return $this->getSessionKey('locale'); } + + /** + * Devolver el color asociado a una cuenta + * + * @return string + */ + public function getAccountColor() + { + return $this->getSessionKey('accountcolor'); + } + + /** + * Establece el color asociado a una cuenta + * + * @param array $color + */ + public function setAccountColor(array $color) + { + $this->setSessionKey('accountcolor', $color); + } } diff --git a/lib/SP/Html/Minify.php b/lib/SP/Html/Minify.php index 67db37cf..7992a65b 100644 --- a/lib/SP/Html/Minify.php +++ b/lib/SP/Html/Minify.php @@ -57,7 +57,7 @@ class Minify * * @var array */ - private $files = array(); + private $files = []; /** * Tipos de archivos a procesar * @@ -74,18 +74,9 @@ class Minify /** * Minify constructor. * - * @throws \ReflectionException - * @throws \SP\Core\Dic\ContainerException - */ - public function __construct() - { - $this->injectDependencies(); - } - - /** * @param Klein $router */ - public function inject(Klein $router) + public function __construct(Klein $router) { $this->router = $router; } diff --git a/lib/SP/Repositories/Account/AccountRepository.php b/lib/SP/Repositories/Account/AccountRepository.php index d8f40e3a..89210620 100644 --- a/lib/SP/Repositories/Account/AccountRepository.php +++ b/lib/SP/Repositories/Account/AccountRepository.php @@ -53,6 +53,23 @@ class AccountRepository extends Repository implements RepositoryItemInterface { use RepositoryItemTrait; + /** + * Devolver el número total de cuentas + * + * @return int + */ + public function getTotalNumAccounts() + { + $query = /** @lang SQL */ + 'SELECT SUM(n) AS num FROM + (SELECT COUNT(*) AS n FROM Account UNION SELECT COUNT(*) AS n FROM AccountHistory) a'; + + $Data = new QueryData(); + $Data->setQuery($query); + + return (int)DbWrapper::getResults($Data)->num; + } + /** * @param $id * @return AccountPassData @@ -629,7 +646,6 @@ class AccountRepository extends Repository implements RepositoryItemInterface return DbWrapper::getResultsArray($queryData, $this->db); } - /** * @param QueryCondition $queryFilter * @return array diff --git a/lib/SP/Repositories/Repository.php b/lib/SP/Repositories/Repository.php index 75bba7db..ac8c3d2a 100644 --- a/lib/SP/Repositories/Repository.php +++ b/lib/SP/Repositories/Repository.php @@ -24,10 +24,10 @@ namespace SP\Repositories; +use SP\Bootstrap; use SP\Config\Config; use SP\Core\Events\EventDispatcher; use SP\Core\Session\Session; -use SP\Core\Traits\InjectableTrait; use SP\Storage\Database; use SP\Storage\DatabaseInterface; @@ -38,8 +38,6 @@ use SP\Storage\DatabaseInterface; */ abstract class Repository { - use InjectableTrait; - /** @var Config */ protected $config; /** @var Session */ @@ -50,28 +48,22 @@ abstract class Repository protected $db; /** - * Service constructor. + * Repository constructor. + * + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ final public function __construct() { - $this->injectDependencies(); + $dic = Bootstrap::getContainer(); + + $this->config = $dic->get(Config::class); + $this->db = $dic->get(Database::class); + $this->session = $dic->get(Session::class); + $this->eventDispatcher = $dic->get(EventDispatcher::class); if (method_exists($this, 'initialize')) { $this->initialize(); } } - - /** - * @param Config $config - * @param Session $session - * @param EventDispatcher $eventDispatcher - * @param Database $db - */ - public function inject(Config $config, Session $session, EventDispatcher $eventDispatcher, Database $db) - { - $this->config = $config; - $this->session = $session; - $this->eventDispatcher = $eventDispatcher; - $this->db = $db; - } } \ No newline at end of file diff --git a/lib/SP/Services/Account/AccountFileService.php b/lib/SP/Services/Account/AccountFileService.php index 4bd78da0..dfbbdf96 100644 --- a/lib/SP/Services/Account/AccountFileService.php +++ b/lib/SP/Services/Account/AccountFileService.php @@ -31,6 +31,7 @@ use SP\DataModel\FileExtData; use SP\DataModel\ItemSearchData; use SP\Mgmt\Files\FileUtil; use SP\Repositories\Account\AccountFileRepository; +use SP\Services\Service; use SP\Util\ImageUtil; /** @@ -38,7 +39,7 @@ use SP\Util\ImageUtil; * * @package SP\Services\Account */ -class AccountFileService +class AccountFileService extends Service { use InjectableTrait; @@ -48,21 +49,12 @@ class AccountFileService protected $accountFileRepository; /** - * AccountFileService constructor. - * - * @throws \SP\Core\Dic\ContainerException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ - public function __construct() + public function initialize() { - $this->injectDependencies(); - } - - /** - * @param AccountFileRepository $accountFileRepository - */ - public function inject(AccountFileRepository $accountFileRepository) - { - $this->accountFileRepository = $accountFileRepository; + $this->accountFileRepository = $this->dic->get(AccountFileRepository::class); } /** diff --git a/lib/SP/Services/Account/AccountHistoryService.php b/lib/SP/Services/Account/AccountHistoryService.php index f9480fc3..d09998f5 100644 --- a/lib/SP/Services/Account/AccountHistoryService.php +++ b/lib/SP/Services/Account/AccountHistoryService.php @@ -24,23 +24,22 @@ namespace SP\Services\Account; +use SP\Core\Exceptions\QueryException; use SP\Core\Exceptions\SPException; -use SP\Core\Traits\InjectableTrait; use SP\DataModel\AccountHistoryData; use SP\DataModel\ItemSearchData; use SP\Repositories\Account\AccountHistoryRepository; use SP\Repositories\Account\AccountToUserGroupRepository; use SP\Repositories\Account\AccountToUserRepository; +use SP\Services\Service; /** * Class AccountHistoryService * * @package SP\Services\Account */ -class AccountHistoryService +class AccountHistoryService extends Service { - use InjectableTrait; - /** * @var AccountHistoryRepository */ @@ -55,27 +54,14 @@ class AccountHistoryService protected $accountToUserRepository; /** - * AccountHistoryService constructor. - * - * @throws \SP\Core\Dic\ContainerException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ - public function __construct() + public function initialize() { - $this->injectDependencies(); - } - - /** - * @param AccountHistoryRepository $accountHistoryRepository - * @param AccountToUserGroupRepository $accountToUserGroupRepository - * @param AccountToUserRepository $accountToUserRepository - */ - public function inject(AccountHistoryRepository $accountHistoryRepository, - AccountToUserGroupRepository $accountToUserGroupRepository, - AccountToUserRepository $accountToUserRepository) - { - $this->accountHistoryRepository = $accountHistoryRepository; - $this->accountToUserGroupRepository = $accountToUserGroupRepository; - $this->accountToUserRepository = $accountToUserRepository; + $this->accountHistoryRepository = $this->dic->get(AccountHistoryRepository::class); + $this->accountToUserRepository = $this->dic->get(AccountToUserRepository::class); + $this->accountToUserGroupRepository = $this->dic->get(AccountToUserGroupRepository::class); } /** @@ -128,4 +114,19 @@ class AccountHistoryService { return $this->accountHistoryRepository->search($itemSearchData); } + + /** + * Crea una nueva cuenta en la BBDD + * + * @param array $itemData ['id' => , 'isModify' => ,'isDelete' => , 'masterPassHash' => ] + * @return bool + * @throws QueryException + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function create($itemData) + { + return $this->accountHistoryRepository->create($itemData); + } + } \ No newline at end of file diff --git a/lib/SP/Services/Account/AccountSearchService.php b/lib/SP/Services/Account/AccountSearchService.php index d6f56ec0..0d42cdc5 100644 --- a/lib/SP/Services/Account/AccountSearchService.php +++ b/lib/SP/Services/Account/AccountSearchService.php @@ -31,8 +31,6 @@ use SP\Account\AccountSearchItem; use SP\Config\ConfigData; use SP\Core\Acl\Acl; use SP\Core\Session\Session; -use SP\Core\SessionFactory; -use SP\Core\Traits\InjectableTrait; use SP\DataModel\AccountSearchVData; use SP\DataModel\Dto\AccountAclDto; use SP\DataModel\Dto\AccountCache; @@ -40,18 +38,17 @@ use SP\Repositories\Account\AccountRepository; use SP\Repositories\Account\AccountToTagRepository; use SP\Repositories\Account\AccountToUserGroupRepository; use SP\Repositories\Account\AccountToUserRepository; -use SP\Repositories\User\UserRepository; -use SP\Repositories\UserGroup\UserGroupRepository; +use SP\Services\Service; +use SP\Services\User\UserService; +use SP\Services\UserGroup\UserGroupService; defined('APP_ROOT') || die(); /** * Class AccountSearchService para la gestión de búsquedas de cuentas */ -class AccountSearchService +class AccountSearchService extends Service { - use InjectableTrait; - /** * Colores para resaltar las cuentas * @@ -102,27 +99,16 @@ class AccountSearchService private $accountRepository; /** - * Constructor + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ - public function __construct() + protected function initialize() { - $this->injectDependencies(); - - $this->accountRepository = new AccountRepository(); - $this->accountToTagRepository = new AccountToTagRepository(); - $this->accountToUserRepository = new AccountToUserRepository(); - $this->accountToUserGroupRepository = new AccountToUserGroupRepository(); - } - - /** - * @param ConfigData $configData - * @param Session $session - */ - public function inject(ConfigData $configData, - Session $session) - { - $this->configData = $configData; - $this->session = $session; + $this->accountRepository = $this->dic->get(AccountRepository::class); + $this->accountToTagRepository = $this->dic->get(AccountToTagRepository::class); + $this->accountToUserRepository = $this->dic->get(AccountToUserRepository::class); + $this->accountToUserGroupRepository = $this->dic->get(AccountToUserGroupRepository::class); + $this->configData = $this->config->getConfigData(); } /** @@ -131,8 +117,10 @@ class AccountSearchService * * @param AccountSearchFilter $accountSearchFilter * @return array - * @throws \SP\Core\Exceptions\SPException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Dic\ContainerException + * @throws \SP\Core\Exceptions\SPException */ public function processSearchResults(AccountSearchFilter $accountSearchFilter) { @@ -144,6 +132,7 @@ class AccountSearchService $maxTextLength = $this->configData->isResultsAsCards() ? 40 : 60; $accountLinkEnabled = $this->session->getUserData()->getPreferences()->isAccountLink() || $this->configData->isAccountLink(); + // FIXME $favorites = AccountFavorites::getFavorites($this->session->getUserData()->getId()); foreach ($accountSearchResponse->getData() as $accountSearchData) { @@ -191,6 +180,8 @@ class AccountSearchService * * @param $txt * @return array|bool + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Exceptions\SPException */ private function analyzeQueryString($txt) @@ -203,7 +194,7 @@ class AccountSearchService switch ($filters['filter']) { case 'user': - $userData = (new UserRepository())->getByLogin($filters['text']); + $userData = $this->dic->get(UserService::class)->getByLogin($filters['text']); if (!is_object($userData)) { return []; @@ -216,7 +207,7 @@ class AccountSearchService ]; break; case 'owner': - $userData = (new UserRepository())->getByLogin($filters['text']); + $userData = $this->dic->get(UserService::class)->getByLogin($filters['text']); if (!is_object($userData)) { return []; @@ -229,7 +220,7 @@ class AccountSearchService ]; break; case 'group': - $userGroupData = (new UserGroupRepository())->getByName($filters['text']); + $userGroupData = $this->dic->get(UserGroupService::class)->getByName($filters['text']); if (!is_object($userGroupData)) { return []; @@ -242,7 +233,7 @@ class AccountSearchService ]; break; case 'maingroup': - $userGroupData = (new UserGroupRepository())->getByName($filters['text']); + $userGroupData = $this->dic->get(UserGroupService::class)->getByName($filters['text']); if (!is_object($userGroupData)) { return []; @@ -313,7 +304,7 @@ class AccountSearchService */ private function pickAccountColor($id) { - $accountColor = SessionFactory::getAccountColor(); + $accountColor = $this->session->getAccountColor(); if (!is_array($accountColor) || !isset($accountColor[$id]) @@ -322,7 +313,7 @@ class AccountSearchService $color = array_rand(self::$colors); $accountColor[$id] = '#' . self::$colors[$color]; - SessionFactory::setAccountColor($accountColor); + $this->session->setAccountColor($accountColor); } return $accountColor[$id]; diff --git a/lib/SP/Services/Account/AccountService.php b/lib/SP/Services/Account/AccountService.php index 7c7bea5c..3a0a935b 100644 --- a/lib/SP/Services/Account/AccountService.php +++ b/lib/SP/Services/Account/AccountService.php @@ -35,16 +35,15 @@ use SP\Core\Crypt\Session as CryptSession; use SP\Core\Exceptions\QueryException; use SP\Core\Exceptions\SPException; use SP\Core\Session\Session; -use SP\Core\Traits\InjectableTrait; use SP\DataModel\Dto\AccountDetailsResponse; use SP\DataModel\ItemSearchData; use SP\Log\Log; -use SP\Repositories\Account\AccountHistoryRepository; use SP\Repositories\Account\AccountRepository; use SP\Repositories\Account\AccountToTagRepository; use SP\Repositories\Account\AccountToUserGroupRepository; use SP\Repositories\Account\AccountToUserRepository; use SP\Services\Config\ConfigService; +use SP\Services\Service; use SP\Services\ServiceItemTrait; /** @@ -52,9 +51,8 @@ use SP\Services\ServiceItemTrait; * * @package SP\Services\Account */ -class AccountService implements AccountServiceInterface +class AccountService extends Service implements AccountServiceInterface { - use InjectableTrait; use ServiceItemTrait; /** @@ -79,33 +77,15 @@ class AccountService implements AccountServiceInterface protected $session; /** - * AccountService constructor. - * - * @throws \SP\Core\Dic\ContainerException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ - public function __construct() + public function initialize() { - $this->injectDependencies(); - } - - /** - * @param AccountRepository $accountRepository - * @param AccountToUserGroupRepository $accountToUserGroupRepository - * @param AccountToUserRepository $accountToUserRepository - * @param AccountToTagRepository $accountToTagRepository - * @param Session $session - */ - public function inject(AccountRepository $accountRepository, - AccountToUserGroupRepository $accountToUserGroupRepository, - AccountToUserRepository $accountToUserRepository, - AccountToTagRepository $accountToTagRepository, - Session $session) - { - $this->accountRepository = $accountRepository; - $this->accountToUserGroupRepository = $accountToUserGroupRepository; - $this->accountToUserRepository = $accountToUserRepository; - $this->accountToTagRepository = $accountToTagRepository; - $this->session = $session; + $this->accountRepository = $this->dic->get(AccountRepository::class); + $this->accountToUserGroupRepository = $this->dic->get(AccountToUserGroupRepository::class); + $this->accountToUserRepository = $this->dic->get(AccountToUserRepository::class); + $this->accountToTagRepository = $this->dic->get(AccountToUserRepository::class); } /** @@ -121,6 +101,8 @@ class AccountService implements AccountServiceInterface /** * @param AccountDetailsResponse $accountDetailsResponse * @return AccountService + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ public function withUsersById(AccountDetailsResponse $accountDetailsResponse) { @@ -224,7 +206,7 @@ class AccountService implements AccountServiceInterface $out['pass'] = Crypt::encrypt($pass, $out['key'], $masterPass); if (strlen($pass) > 1000 || strlen($out['key']) > 1000) { - throw new QueryException(SPException::ERROR, __u('Error interno')); + throw new QueryException(__u('Error interno'), SPException::ERROR); } return $out; @@ -255,7 +237,7 @@ class AccountService implements AccountServiceInterface $this->accountToTagRepository->add($accountRequest); } } catch (SPException $e) { - Log::writeNewLog(__FUNCTION__, $e->getMessage(), Log::ERROR); + debugLog($e->getMessage()); } } @@ -263,8 +245,13 @@ class AccountService implements AccountServiceInterface * Updates external items for the account * * @param AccountRequest $accountRequest + * @throws QueryException * @throws SPException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Dic\ContainerException + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Services\Config\ParameterNotFoundException */ public function update(AccountRequest $accountRequest) { @@ -286,17 +273,21 @@ class AccountService implements AccountServiceInterface * @param bool $isDelete * @return bool * @throws QueryException - * @throws \SP\Core\Dic\ContainerException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Exceptions\ConstraintException * @throws \SP\Services\Config\ParameterNotFoundException */ protected function addHistory($accountId, $isDelete = false) { - return (new AccountHistoryRepository())->create([ + $accountHistoryRepository = $this->dic->get(AccountHistoryService::class); + $configService = $this->dic->get(ConfigService::class); + + return $accountHistoryRepository->create([ 'id' => $accountId, 'isDelete' => (int)$isDelete, 'isModify' => (int)!$isDelete, - 'masterPassHash' => (new ConfigService())->getByParam('masterPwd') + 'masterPassHash' => $configService->getByParam('masterPwd') ]); } @@ -329,7 +320,7 @@ class AccountService implements AccountServiceInterface $this->accountToTagRepository->deleteByAccountId($accountRequest->id); } } catch (SPException $e) { - Log::writeNewLog(__FUNCTION__, $e->getMessage(), Log::ERROR); + debugLog($e->getMessage()); } } @@ -337,7 +328,8 @@ class AccountService implements AccountServiceInterface * @param AccountRequest $accountRequest * @throws QueryException * @throws SPException - * @throws \SP\Core\Dic\ContainerException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Exceptions\ConstraintException * @throws \SP\Services\Config\ParameterNotFoundException */ @@ -357,7 +349,8 @@ class AccountService implements AccountServiceInterface * @param $historyId * @param $accountId * @throws QueryException - * @throws \SP\Core\Dic\ContainerException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Exceptions\ConstraintException * @throws \SP\Services\Config\ParameterNotFoundException */ @@ -385,6 +378,7 @@ class AccountService implements AccountServiceInterface * @param int $actionId * @return \SP\Core\Messages\LogMessage * @throws SPException + * @throws \SP\Core\Dic\ContainerException */ public function logAction($id, $actionId) { @@ -455,4 +449,26 @@ class AccountService implements AccountServiceInterface { return $this->accountRepository->search($itemSearchData); } + + /** + * Devolver el número total de cuentas + * + * @return int + */ + public function getTotalNumAccounts() + { + return $this->accountRepository->getTotalNumAccounts(); + } + + /** + * Obtener los datos de una cuenta. + * + * @param $id + * @return \SP\DataModel\AccountExtData + * @throws SPException + */ + public function getDataForLink($id) + { + return $this->accountRepository->getDataForLink($id); + } } \ No newline at end of file diff --git a/lib/SP/Services/Auth/LoginService.php b/lib/SP/Services/Auth/LoginService.php index cdfa34e2..2fc32863 100644 --- a/lib/SP/Services/Auth/LoginService.php +++ b/lib/SP/Services/Auth/LoginService.php @@ -29,13 +29,10 @@ defined('APP_ROOT') || die(); use Defuse\Crypto\Exception\BadFormatException; use Defuse\Crypto\Exception\CryptoException; use SP\Bootstrap; -use SP\Config\Config; -use SP\Core\Events\EventDispatcher; +use SP\Config\ConfigData; use SP\Core\Exceptions\SPException; use SP\Core\Language; use SP\Core\Messages\LogMessage; -use SP\Core\Session\Session; -use SP\Core\Traits\InjectableTrait; use SP\Core\UI\Theme; use SP\Crypt\TemporaryMasterPass; use SP\DataModel\TrackData; @@ -66,10 +63,8 @@ use SP\Util\Util; * * @package SP\Services */ -class LoginService +class LoginService extends Service { - use InjectableTrait; - /** * Estados */ @@ -98,13 +93,9 @@ class LoginService */ protected $LogMessage; /** - * @var $ConfigData + * @var ConfigData */ protected $configData; - /** - * @var Config - */ - protected $config; /** * @var Theme */ @@ -117,49 +108,23 @@ class LoginService * @var Language */ protected $language; - /** - * @var Session - */ - private $session; - /** - * @var EventDispatcher - */ - private $eventDispatcher; /** - * LoginController constructor. - * - * @param Config $config - * @param Session $session - * @param Theme $theme - * @param EventDispatcher $eventDispatcher - * @throws \SP\Core\Dic\ContainerException - * @throws \ReflectionException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ - public function __construct(Config $config, Session $session, Theme $theme, EventDispatcher $eventDispatcher) + public function initialize() { - $this->injectDependencies(); - - $this->config = $config; - $this->configData = $config->getConfigData(); - $this->theme = $theme; - $this->session = $session; - $this->eventDispatcher = $eventDispatcher; + $this->configData = $this->config->getConfigData(); + $this->theme = $this->dic->get(Theme::class); + $this->userService = $this->dic->get(UserService::class); + $this->language = $this->dic->get(Language::class); $this->jsonResponse = new JsonResponse(); $this->LogMessage = new LogMessage(); $this->userLoginData = new UserLoginData(); $this->LogMessage->setAction(__u('Inicio sesión')); - } - /** - * @param UserService $userService - * @param Language $language - */ - public function inject(UserService $userService, Language $language) - { - $this->userService = $userService; - $this->language = $language; } /** @@ -169,7 +134,6 @@ class LoginService * @throws \Defuse\Crypto\Exception\EnvironmentIsBrokenException * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface - * @throws \ReflectionException */ public function doLogin() { @@ -319,14 +283,12 @@ class LoginService * @throws SPException * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface - * @throws \ReflectionException - * @throws \SP\Core\Dic\ContainerException * @throws \SP\Services\Config\ParameterNotFoundException */ protected function loadMasterPass() { - $temporaryMasterPass = new TemporaryMasterPass(); - $userPassService = new UserPassService(); + $temporaryMasterPass = $this->dic->get(TemporaryMasterPass::class); + $userPassService = $this->dic->get(UserPassService::class); $masterPass = Request::analyzeEncrypted('mpass'); $oldPass = Request::analyzeEncrypted('oldpass'); @@ -386,8 +348,10 @@ class LoginService /** * Cargar la sesión del usuario * - * @throws \SP\Core\Exceptions\SPException - * @throws \SP\Core\Dic\ContainerException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException */ protected function setUserSession() { @@ -398,7 +362,7 @@ class LoginService // Cargar las variables de ussuario en la sesión $this->session->setUserData($userLoginResponse); - $this->session->setUserProfile((new UserProfileService())->getById($userLoginResponse->getUserProfileId())); + $this->session->setUserProfile($this->dic->get(UserProfileService::class)->getById($userLoginResponse->getUserProfileId())); if ($this->configData->isDemoEnabled()) { $userLoginResponse->setPreferences(new UserPreferencesData()); @@ -419,8 +383,6 @@ class LoginService $this->theme->initTheme(true); -// SessionFactory::setSessionType(SessionFactory::SESSION_INTERACTIVE); - $this->session->setAuthCompleted(true); $this->eventDispatcher->notifyEvent('login.preferences', $this); @@ -437,18 +399,18 @@ class LoginService /** * Autentificación LDAP * - * @param LdapAuthData $AuthData + * @param LdapAuthData $authData * @return bool * @throws \SP\Core\Exceptions\SPException * @throws AuthException */ - protected function authLdap(LdapAuthData $AuthData) + protected function authLdap(LdapAuthData $authData) { - if ($AuthData->getStatusCode() > 0) { + if ($authData->getStatusCode() > 0) { $this->LogMessage->addDetails(__u('Tipo'), __FUNCTION__); $this->LogMessage->addDetails(__u('Usuario'), $this->userLoginData->getLoginUser()); - if ($AuthData->getStatusCode() === 49) { + if ($authData->getStatusCode() === 49) { $this->LogMessage->addDescription(__u('Login incorrecto')); $this->addTracking(); @@ -456,19 +418,19 @@ class LoginService throw new AuthException($this->LogMessage->getDescription(), SPException::INFO, null, self::STATUS_INVALID_LOGIN); } - if ($AuthData->getStatusCode() === 701) { + if ($authData->getStatusCode() === 701) { $this->LogMessage->addDescription(__u('Cuenta expirada')); throw new AuthException($this->LogMessage->getDescription(), SPException::INFO, null, self::STATUS_USER_DISABLED); } - if ($AuthData->getStatusCode() === 702) { + if ($authData->getStatusCode() === 702) { $this->LogMessage->addDescription(__u('El usuario no tiene grupos asociados')); throw new AuthException($this->LogMessage->getDescription(), SPException::INFO, null, self::STATUS_USER_DISABLED); } - if ($AuthData->isAuthGranted() === false) { + if ($authData->isAuthGranted() === false) { return false; } @@ -478,14 +440,14 @@ class LoginService } $this->LogMessage->addDetails(__u('Tipo'), __FUNCTION__); - $this->LogMessage->addDetails(__u('Servidor LDAP'), $AuthData->getServer()); + $this->LogMessage->addDetails(__u('Servidor LDAP'), $authData->getServer()); try { $userLoginRequest = new UserLoginRequest(); $userLoginRequest->setLogin($this->userLoginData->getLoginUser()); $userLoginRequest->setPassword($this->userLoginData->getLoginPass()); - $userLoginRequest->setEmail($AuthData->getEmail()); - $userLoginRequest->setName($AuthData->getName()); + $userLoginRequest->setEmail($authData->getEmail()); + $userLoginRequest->setName($authData->getName()); $userLoginRequest->setIsLdap(1); @@ -509,16 +471,16 @@ class LoginService /** * Autentificación en BD * - * @param DatabaseAuthData $AuthData + * @param DatabaseAuthData $authData * @return bool * @throws \SP\Core\Exceptions\SPException * @throws AuthException */ - protected function authDatabase(DatabaseAuthData $AuthData) + protected function authDatabase(DatabaseAuthData $authData) { // Autentificamos con la BBDD - if ($AuthData->getAuthenticated() === 0) { - if ($AuthData->isAuthGranted() === false) { + if ($authData->getAuthenticated() === 0) { + if ($authData->isAuthGranted() === false) { return false; } @@ -530,7 +492,7 @@ class LoginService throw new AuthException($this->LogMessage->getDescription(), SPException::INFO, null, self::STATUS_INVALID_LOGIN); } - if ($AuthData->getAuthenticated() === 1) { + if ($authData->getAuthenticated() === 1) { $this->LogMessage->addDetails(__u('Tipo'), __FUNCTION__); } diff --git a/lib/SP/Services/AuthToken/AuthTokenService.php b/lib/SP/Services/AuthToken/AuthTokenService.php index 3702dcba..fe65ebf1 100644 --- a/lib/SP/Services/AuthToken/AuthTokenService.php +++ b/lib/SP/Services/AuthToken/AuthTokenService.php @@ -29,11 +29,10 @@ use SP\Core\Crypt\Hash; use SP\Core\Crypt\Session as CryptSession; use SP\Core\Crypt\Vault; use SP\Core\Exceptions\SPException; -use SP\Core\Session\Session; -use SP\Core\Traits\InjectableTrait; use SP\DataModel\AuthTokenData; use SP\DataModel\ItemSearchData; use SP\Repositories\AuthToken\AuthTokenRepository; +use SP\Services\Service; use SP\Services\ServiceItemTrait; use SP\Util\Util; @@ -42,38 +41,23 @@ use SP\Util\Util; * * @package SP\Services\AuthToken */ -class AuthTokenService +class AuthTokenService extends Service { - use InjectableTrait; use ServiceItemTrait; /** * @var AuthTokenRepository */ protected $authTokenRepository; - /** - * @var Session - */ - protected $session; + /** - * CategoryService constructor. - * - * @throws \SP\Core\Dic\ContainerException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ - public function __construct() + protected function initialize() { - $this->injectDependencies(); - } - - /** - * @param AuthTokenRepository $apiTokenRepository - * @param Session $session - */ - public function inject(AuthTokenRepository $apiTokenRepository, Session $session) - { - $this->authTokenRepository = $apiTokenRepository; - $this->session = $session; + $this->authTokenRepository = $this->dic->get(AuthTokenRepository::class); } /** diff --git a/lib/SP/Services/Category/CategoryService.php b/lib/SP/Services/Category/CategoryService.php index 1c756e28..2cb88764 100644 --- a/lib/SP/Services/Category/CategoryService.php +++ b/lib/SP/Services/Category/CategoryService.php @@ -25,9 +25,9 @@ namespace SP\Services\Category; use SP\Core\Exceptions\SPException; -use SP\Core\Traits\InjectableTrait; use SP\DataModel\ItemSearchData; use SP\Repositories\Category\CategoryRepository; +use SP\Services\Service; use SP\Services\ServiceItemTrait; /** @@ -35,9 +35,8 @@ use SP\Services\ServiceItemTrait; * * @package SP\Services\Category */ -class CategoryService +class CategoryService extends Service { - use InjectableTrait; use ServiceItemTrait; /** @@ -46,15 +45,12 @@ class CategoryService protected $categoryRepository; /** - * CategoryService constructor. - * - * @throws \SP\Core\Dic\ContainerException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ - public function __construct() + public function initialize() { - $this->injectDependencies(); - - $this->categoryRepository = new CategoryRepository(); + $this->categoryRepository = $this->dic->get(CategoryRepository::class); } /** @@ -98,7 +94,6 @@ class CategoryService * @throws SPException * @throws \SP\Core\Exceptions\ConstraintException * @throws \SP\Core\Exceptions\QueryException - * @throws \SP\Core\Dic\ContainerException */ public function create($itemData) { @@ -111,7 +106,6 @@ class CategoryService * @throws SPException * @throws \SP\Core\Exceptions\ConstraintException * @throws \SP\Core\Exceptions\QueryException - * @throws \SP\Core\Dic\ContainerException */ public function update($itemData) { diff --git a/lib/SP/Services/Client/ClientService.php b/lib/SP/Services/Client/ClientService.php index 5981de6e..3d6c183e 100644 --- a/lib/SP/Services/Client/ClientService.php +++ b/lib/SP/Services/Client/ClientService.php @@ -27,9 +27,9 @@ namespace SP\Services\Client; use SP\Account\AccountUtil; use SP\Core\Exceptions\SPException; use SP\Core\Session\Session; -use SP\Core\Traits\InjectableTrait; use SP\DataModel\ItemSearchData; use SP\Repositories\Client\ClientRepository; +use SP\Services\Service; use SP\Services\ServiceItemTrait; /** @@ -37,9 +37,8 @@ use SP\Services\ServiceItemTrait; * * @package SP\Services\Client */ -class ClientService +class ClientService extends Service { - use InjectableTrait; use ServiceItemTrait; /** @@ -52,23 +51,12 @@ class ClientService protected $session; /** - * ClientService constructor. - * - * @throws \SP\Core\Dic\ContainerException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ - public function __construct() + protected function initialize() { - $this->injectDependencies(); - } - - /** - * @param ClientRepository $clientRepository - * @param Session $session - */ - public function inject(ClientRepository $clientRepository, Session $session) - { - $this->clientRepository = $clientRepository; - $this->session = $session; + $this->clientRepository = $this->dic->get(ClientRepository::class); } /** diff --git a/lib/SP/Services/Config/ConfigService.php b/lib/SP/Services/Config/ConfigService.php index 28e8a396..b5a1cabb 100644 --- a/lib/SP/Services/Config/ConfigService.php +++ b/lib/SP/Services/Config/ConfigService.php @@ -31,6 +31,7 @@ use SP\Core\Traits\InjectableTrait; use SP\DataModel\ConfigData; use SP\DataModel\Dto\ConfigRequest; use SP\Repositories\Config\ConfigRepository; +use SP\Services\Service; use SP\Services\ServiceException; /** @@ -38,7 +39,7 @@ use SP\Services\ServiceException; * * @package SP\Services\Config */ -class ConfigService +class ConfigService extends Service { use InjectableTrait; @@ -48,22 +49,12 @@ class ConfigService protected $configRepository; /** - * ConfigService constructor. - * - * @throws \SP\Core\Dic\ContainerException - * @throws \ReflectionException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ - public function __construct() + protected function initialize() { - $this->injectDependencies(); - } - - /** - * @param ConfigRepository $configRepository - */ - public function inject(ConfigRepository $configRepository) - { - $this->configRepository = $configRepository; + $this->configRepository = $this->dic->get(ConfigRepository::class); } /** diff --git a/lib/SP/Services/CustomField/CustomFieldDefService.php b/lib/SP/Services/CustomField/CustomFieldDefService.php index a881bb84..b943a2c3 100644 --- a/lib/SP/Services/CustomField/CustomFieldDefService.php +++ b/lib/SP/Services/CustomField/CustomFieldDefService.php @@ -24,9 +24,9 @@ namespace SP\Services\CustomField; -use SP\Core\Traits\InjectableTrait; use SP\DataModel\ItemSearchData; use SP\Repositories\CustomField\CustomFieldDefRepository; +use SP\Services\Service; use SP\Services\ServiceItemTrait; /** @@ -34,9 +34,8 @@ use SP\Services\ServiceItemTrait; * * @package SP\Services\CustomField */ -class CustomFieldDefService +class CustomFieldDefService extends Service { - use InjectableTrait; use ServiceItemTrait; /** @@ -45,21 +44,12 @@ class CustomFieldDefService protected $customFieldDefRepository; /** - * ClientService constructor. - * - * @throws \SP\Core\Dic\ContainerException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ - public function __construct() + protected function initialize() { - $this->injectDependencies(); - } - - /** - * @param CustomFieldDefRepository $customFieldDefRepository - */ - public function inject(CustomFieldDefRepository $customFieldDefRepository) - { - $this->customFieldDefRepository = $customFieldDefRepository; + $this->customFieldDefRepository = $this->dic->get(CustomFieldDefRepository::class); } /** diff --git a/lib/SP/Services/PublicLink/PublicLinkService.php b/lib/SP/Services/PublicLink/PublicLinkService.php index 36973a12..0cffaaae 100644 --- a/lib/SP/Services/PublicLink/PublicLinkService.php +++ b/lib/SP/Services/PublicLink/PublicLinkService.php @@ -30,13 +30,12 @@ use SP\Core\Crypt\Crypt; use SP\Core\Crypt\Session as CryptSession; use SP\Core\Crypt\Vault; use SP\Core\Exceptions\SPException; -use SP\Core\Session\Session; -use SP\Core\Traits\InjectableTrait; use SP\DataModel\ItemSearchData; use SP\DataModel\PublicLinkData; use SP\Http\Request; -use SP\Repositories\Account\AccountRepository; use SP\Repositories\PublicLink\PublicLinkRepository; +use SP\Services\Account\AccountService; +use SP\Services\Service; use SP\Services\ServiceItemTrait; use SP\Util\Checks; use SP\Util\HttpUtil; @@ -47,33 +46,14 @@ use SP\Util\Util; * * @package SP\Services\PublicLink */ -class PublicLinkService +class PublicLinkService extends Service { - use InjectableTrait; use ServiceItemTrait; /** * @var PublicLinkRepository */ protected $publicLinkRepository; - /** - * @var Config - */ - protected $config; - /** - * @var Session - */ - protected $session; - - /** - * CategoryService constructor. - * - * @throws \SP\Core\Dic\ContainerException - */ - public function __construct() - { - $this->injectDependencies(); - } /** * Returns an HTTP URL for given hash @@ -97,15 +77,12 @@ class PublicLinkService } /** - * @param PublicLinkRepository $publicLinkRepository - * @param Config $config - * @param Session $session + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ - public function inject(PublicLinkRepository $publicLinkRepository, Config $config, Session $session) + protected function initialize() { - $this->publicLinkRepository = $publicLinkRepository; - $this->config = $config; - $this->session = $session; + $this->publicLinkRepository = $this->dic->get(PublicLinkRepository::class); } /** @@ -177,14 +154,15 @@ class PublicLinkService * @param int $itemId * @param string $linkKey * @return Vault - * @throws SPException * @throws \Defuse\Crypto\Exception\CryptoException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface + * @throws SPException */ protected function getSecuredLinkData($itemId, $linkKey) { // Obtener los datos de la cuenta - $accountService = new AccountRepository(); - $accountData = $accountService->getDataForLink($itemId); + $accountData = $this->dic->get(AccountService::class)->getDataForLink($itemId); // Desencriptar la clave de la cuenta $key = CryptSession::getSessionKey(); @@ -228,6 +206,8 @@ class PublicLinkService * @return int * @throws SPException * @throws \Defuse\Crypto\Exception\CryptoException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Exceptions\ConstraintException * @throws \SP\Core\Exceptions\QueryException */ diff --git a/lib/SP/Services/Service.php b/lib/SP/Services/Service.php index d9e5bc01..68b03ee0 100644 --- a/lib/SP/Services/Service.php +++ b/lib/SP/Services/Service.php @@ -24,12 +24,11 @@ namespace SP\Services; +use Psr\Container\ContainerInterface; +use SP\Bootstrap; use SP\Config\Config; use SP\Core\Events\EventDispatcher; use SP\Core\Session\Session; -use SP\Core\Traits\InjectableTrait; -use SP\Storage\Database; -use SP\Storage\DatabaseInterface; /** * Class Service @@ -38,8 +37,6 @@ use SP\Storage\DatabaseInterface; */ abstract class Service { - use InjectableTrait; - const STATUS_INTERNAL_ERROR = 1000; /** @@ -55,33 +52,26 @@ abstract class Service */ protected $eventDispatcher; /** - * @var DatabaseInterface + * @var ContainerInterface */ - protected $db; + protected $dic; /** * Service constructor. + * + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ final public function __construct() { - $this->injectDependencies(); + $this->dic = Bootstrap::getContainer(); + + $this->config = $this->dic->get(Config::class); + $this->session = $this->dic->get(Session::class); + $this->eventDispatcher = $this->dic->get(EventDispatcher::class); if (method_exists($this, 'initialize')) { $this->initialize(); } } - - /** - * @param Config $config - * @param Session $session - * @param EventDispatcher $eventDispatcher - * @param Database $db - */ - public function inject(Config $config, Session $session, EventDispatcher $eventDispatcher, Database $db) - { - $this->config = $config; - $this->session = $session; - $this->eventDispatcher = $eventDispatcher; - $this->db = $db; - } } \ No newline at end of file diff --git a/lib/SP/Services/ServiceItemTrait.php b/lib/SP/Services/ServiceItemTrait.php index 675535e6..e2676c71 100644 --- a/lib/SP/Services/ServiceItemTrait.php +++ b/lib/SP/Services/ServiceItemTrait.php @@ -24,6 +24,7 @@ namespace SP\Services; +use SP\Bootstrap; use SP\DataModel\DataModelInterface; /** @@ -37,10 +38,12 @@ trait ServiceItemTrait * Returns service items for a select * * @return DataModelInterface[] + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ public static function getItemsBasic() { - return (new static())->getAllBasic(); + return Bootstrap::getContainer()->get(static::class)->getAllBasic(); } /** diff --git a/lib/SP/Services/Tag/TagService.php b/lib/SP/Services/Tag/TagService.php index ebfc6367..0ffacb05 100644 --- a/lib/SP/Services/Tag/TagService.php +++ b/lib/SP/Services/Tag/TagService.php @@ -25,9 +25,9 @@ namespace SP\Services\Tag; use SP\Core\Exceptions\SPException; -use SP\Core\Traits\InjectableTrait; use SP\DataModel\ItemSearchData; use SP\Repositories\Tag\TagRepository; +use SP\Services\Service; use SP\Services\ServiceItemTrait; /** @@ -35,9 +35,8 @@ use SP\Services\ServiceItemTrait; * * @package SP\Services\Tag */ -class TagService +class TagService extends Service { - use InjectableTrait; use ServiceItemTrait; /** @@ -45,23 +44,13 @@ class TagService */ protected $tagRepository; - /** - * TagService constructor. - * - * @throws \SP\Core\Dic\ContainerException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ - public function __construct() + protected function initialize() { - $this->injectDependencies(); - } - - /** - * @param TagRepository $tagRepository - */ - public function inject(TagRepository $tagRepository) - { - $this->tagRepository = $tagRepository; + $this->tagRepository = $this->dic->get(TagRepository::class); } /** diff --git a/lib/SP/Services/User/UserPassService.php b/lib/SP/Services/User/UserPassService.php index 1c4c85d0..d57f2be9 100644 --- a/lib/SP/Services/User/UserPassService.php +++ b/lib/SP/Services/User/UserPassService.php @@ -25,13 +25,11 @@ namespace SP\Services\User; use Defuse\Crypto\Exception\CryptoException; -use SP\Config\Config; use SP\Config\ConfigData; use SP\Core\Crypt\Crypt; use SP\Core\Crypt\Hash; use SP\Core\Crypt\Session as CryptSession; use SP\Core\Exceptions\SPException; -use SP\Core\Traits\InjectableTrait; use SP\Core\Upgrade\Crypt as CryptUpgrade; use SP\Core\Upgrade\User as UpgradeUser; use SP\DataModel\UserLoginData; @@ -44,10 +42,8 @@ use SP\Services\Service; * * @package SP\Services\User */ -class UserPassService +class UserPassService extends Service { - use InjectableTrait; - // La clave maestra incorrecta const MPASS_WRONG = 0; // La clave maestra correcta @@ -73,26 +69,14 @@ class UserPassService protected $configService; /** - * UserPassService constructor. - * - * @throws \SP\Core\Dic\ContainerException - * @throws \ReflectionException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ - public function __construct() + protected function initialize() { - $this->injectDependencies(); - } - - /** - * @param Config $config - * @param UserRepository $userRepository - * @param ConfigService $configService - */ - public function inject(Config $config, UserRepository $userRepository, ConfigService $configService) - { - $this->configData = $config->getConfigData(); - $this->userRepository = $userRepository; - $this->configService = $configService; + $this->configData = $this->config->getConfigData(); + $this->userRepository = $this->dic->get(UserRepository::class); + $this->configService = $this->dic->get(ConfigService::class);; } /** diff --git a/lib/SP/Services/User/UserService.php b/lib/SP/Services/User/UserService.php index db9d0110..1e2ba170 100644 --- a/lib/SP/Services/User/UserService.php +++ b/lib/SP/Services/User/UserService.php @@ -26,11 +26,11 @@ namespace SP\Services\User; use SP\Core\Crypt\Hash; use SP\Core\Exceptions\SPException; -use SP\Core\Traits\InjectableTrait; use SP\DataModel\ItemSearchData; use SP\DataModel\UserData; use SP\DataModel\UserPreferencesData; use SP\Repositories\User\UserRepository; +use SP\Services\Service; use SP\Services\ServiceItemTrait; use SP\Util\Util; @@ -39,9 +39,8 @@ use SP\Util\Util; * * @package SP\Services\User */ -class UserService +class UserService extends Service { - use InjectableTrait; use ServiceItemTrait; /** @@ -54,23 +53,13 @@ class UserService protected $userPassService; /** - * UserService constructor. - * - * @throws \SP\Core\Dic\ContainerException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ - public function __construct() + protected function initialize() { - $this->injectDependencies(); - } - - /** - * @param UserRepository $userRepository - * @param UserPassService $userPassService - */ - public function inject(UserRepository $userRepository, UserPassService $userPassService) - { - $this->userRepository = $userRepository; - $this->userPassService = $userPassService; + $this->userRepository = $this->dic->get(UserRepository::class); + $this->userPassService = $this->dic->get(UserPassService::class); } /** diff --git a/lib/SP/Services/UserGroup/UserGroupService.php b/lib/SP/Services/UserGroup/UserGroupService.php index 86c049b2..21cbb3bb 100644 --- a/lib/SP/Services/UserGroup/UserGroupService.php +++ b/lib/SP/Services/UserGroup/UserGroupService.php @@ -26,9 +26,10 @@ namespace SP\Services\UserGroup; use SP\Core\Exceptions\SPException; -use SP\Core\Traits\InjectableTrait; use SP\DataModel\ItemSearchData; +use SP\DataModel\UserGroupData; use SP\Repositories\UserGroup\UserGroupRepository; +use SP\Services\Service; use SP\Services\ServiceItemTrait; /** @@ -36,9 +37,8 @@ use SP\Services\ServiceItemTrait; * * @package SP\Services\UserGroup */ -class UserGroupService +class UserGroupService extends Service { - use InjectableTrait; use ServiceItemTrait; /** @@ -46,23 +46,13 @@ class UserGroupService */ protected $userGroupRepository; - /** - * UserGroup constructor. - * - * @throws \SP\Core\Dic\ContainerException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ - public function __construct() + protected function initialize() { - $this->injectDependencies(); - } - - /** - * @param UserGroupRepository $userGroupRepository - */ - public function inject(UserGroupRepository $userGroupRepository) - { - $this->userGroupRepository = $userGroupRepository; + $this->userGroupRepository = $this->dic->get(UserGroupRepository::class); } /** @@ -128,4 +118,15 @@ class UserGroupService { return $this->userGroupRepository->getAll(); } + + /** + * Returns the item for given name + * + * @param string $name + * @return UserGroupData + */ + public function getByName($name) + { + return $this->userGroupRepository->getByName($name); + } } \ No newline at end of file diff --git a/lib/SP/Services/UserGroup/UserToUserGroupService.php b/lib/SP/Services/UserGroup/UserToUserGroupService.php index 191078c2..e6cafc8e 100644 --- a/lib/SP/Services/UserGroup/UserToUserGroupService.php +++ b/lib/SP/Services/UserGroup/UserToUserGroupService.php @@ -24,40 +24,28 @@ namespace SP\Services\UserGroup; -use SP\Core\Traits\InjectableTrait; use SP\Repositories\UserGroup\UserToUserGroupRepository; -use SP\Services\ServiceItemTrait; +use SP\Services\Service; /** * Class UserToUserGroupService * * @package SP\Services\UserGroup */ -class UserToUserGroupService +class UserToUserGroupService extends Service { - use InjectableTrait; - /** * @var UserToUserGroupRepository */ protected $userToUserGroupRepository; /** - * UserGroup constructor. - * - * @throws \SP\Core\Dic\ContainerException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ - public function __construct() + protected function initialize() { - $this->injectDependencies(); - } - - /** - * @param UserToUserGroupRepository $userToUserGroupRepository - */ - public function inject(UserToUserGroupRepository $userToUserGroupRepository) - { - $this->userToUserGroupRepository = $userToUserGroupRepository; + $this->userToUserGroupRepository = $this->dic->get(UserToUserGroupRepository::class); } /** diff --git a/lib/SP/Services/UserPassRecover/UserPassRecoverService.php b/lib/SP/Services/UserPassRecover/UserPassRecoverService.php index bc905683..332bb381 100644 --- a/lib/SP/Services/UserPassRecover/UserPassRecoverService.php +++ b/lib/SP/Services/UserPassRecover/UserPassRecoverService.php @@ -24,18 +24,16 @@ namespace SP\Services\UserPassRecover; -use SP\Core\Traits\InjectableTrait; use SP\Repositories\UserPassRecover\UserPassRecoverRepository; +use SP\Services\Service; /** * Class UserPassRecoverService * * @package SP\Services\UserPassRecover */ -class UserPassRecoverService +class UserPassRecoverService extends Service { - use InjectableTrait; - /** * Tiempo máximo para recuperar la clave */ @@ -53,19 +51,12 @@ class UserPassRecoverService protected $userPassRecoverRepository; /** - * UserPassRecoverService constructor. + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ - public function __construct() + protected function initialize() { - $this->injectDependencies(); - } - - /** - * @param UserPassRecoverRepository $userPassRecoverRepository - */ - public function inject(UserPassRecoverRepository $userPassRecoverRepository) - { - $this->userPassRecoverRepository = $userPassRecoverRepository; + $this->userPassRecoverRepository = $this->dic->get(UserPassRecoverRepository::class); } /** diff --git a/lib/SP/Services/UserProfile/UserProfileService.php b/lib/SP/Services/UserProfile/UserProfileService.php index 2f456fa9..bc19f02d 100644 --- a/lib/SP/Services/UserProfile/UserProfileService.php +++ b/lib/SP/Services/UserProfile/UserProfileService.php @@ -29,6 +29,7 @@ use SP\Core\Traits\InjectableTrait; use SP\DataModel\ItemSearchData; use SP\DataModel\ProfileData; use SP\Repositories\UserProfile\UserProfileRepository; +use SP\Services\Service; use SP\Services\ServiceItemTrait; use SP\Util\Util; @@ -37,7 +38,7 @@ use SP\Util\Util; * * @package SP\Services\UserProfile */ -class UserProfileService +class UserProfileService extends Service { use InjectableTrait; use ServiceItemTrait; @@ -48,23 +49,12 @@ class UserProfileService protected $userProfileRepository; /** - * UserProfileService constructor. - * - * @throws \SP\Core\Dic\ContainerException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ - public function __construct() + protected function initialize() { - $this->injectDependencies(); - - $this->userProfileRepository = new UserProfileRepository(); - } - - /** - * @param UserProfileRepository $userProfileRepository - */ - public function inject(UserProfileRepository $userProfileRepository) - { - $this->userProfileRepository = $userProfileRepository; + $this->userProfileRepository = $this->dic->get(UserProfileRepository::class); } /**