refactor: [WIP] Use hexagonal architecture and implement interfaces for services and repositories.

Controllers are being splited into commands to better dependency management.

Signed-off-by: Rubén D <nuxsmin@syspass.org>
This commit is contained in:
Rubén D
2022-06-06 08:17:34 +02:00
parent a6e34f7b25
commit 1c8fb0ea1a
629 changed files with 18541 additions and 9626 deletions

View File

@@ -24,16 +24,26 @@
namespace SP\Modules\Web\Controllers;
use DI\DependencyException;
use DI\NotFoundException;
use Klein\Klein;
use SP\Core\Acl\Acl;
use SP\Core\Acl\ActionsInterface;
use SP\Core\Application;
use SP\Core\Events\Event;
use SP\Core\Exceptions\ConstraintException;
use SP\Core\Exceptions\QueryException;
use SP\Core\Exceptions\SessionTimeout;
use SP\Core\PhpExtensionChecker;
use SP\Core\UI\ThemeInterface;
use SP\DataModel\ItemSearchData;
use SP\Domain\Account\AccountFileServiceInterface;
use SP\Domain\Account\AccountHistoryServiceInterface;
use SP\Domain\Account\AccountServiceInterface;
use SP\Domain\Category\CategoryServiceInterface;
use SP\Domain\Client\ClientServiceInterface;
use SP\Domain\CustomField\CustomFieldDefServiceInterface;
use SP\Domain\ItemPreset\ItemPresetServiceInterface;
use SP\Domain\Tag\TagServiceInterface;
use SP\Html\DataGrid\DataGridTab;
use SP\Http\RequestInterface;
use SP\Modules\Web\Controllers\Helpers\Grid\AccountGrid;
use SP\Modules\Web\Controllers\Helpers\Grid\AccountHistoryGrid;
use SP\Modules\Web\Controllers\Helpers\Grid\CategoryGrid;
@@ -42,16 +52,10 @@ use SP\Modules\Web\Controllers\Helpers\Grid\CustomFieldGrid;
use SP\Modules\Web\Controllers\Helpers\Grid\FileGrid;
use SP\Modules\Web\Controllers\Helpers\Grid\ItemPresetGrid;
use SP\Modules\Web\Controllers\Helpers\Grid\TagGrid;
use SP\Modules\Web\Controllers\Helpers\LayoutHelper;
use SP\Modules\Web\Controllers\Helpers\TabsGridHelper;
use SP\Services\Account\AccountFileService;
use SP\Services\Account\AccountHistoryService;
use SP\Services\Account\AccountService;
use SP\Services\Auth\AuthException;
use SP\Services\Category\CategoryService;
use SP\Services\Client\ClientService;
use SP\Services\CustomField\CustomFieldDefService;
use SP\Services\ItemPreset\ItemPresetService;
use SP\Services\Tag\TagService;
use SP\Mvc\View\TemplateInterface;
use SP\Providers\Auth\Browser\BrowserAuthInterface;
/**
* Class ItemManagerController
@@ -60,12 +64,87 @@ use SP\Services\Tag\TagService;
*/
final class ItemManagerController extends ControllerBase
{
protected ?ItemSearchData $itemSearchData = null;
protected ?TabsGridHelper $tabsGridHelper = null;
protected ?ItemSearchData $itemSearchData = null;
private TabsGridHelper $tabsGridHelper;
private CategoryServiceInterface $categoryService;
private TagServiceInterface $tagService;
private ClientServiceInterface $clientService;
private CustomFieldDefServiceInterface $customFieldDefService;
private AccountFileServiceInterface $accountFileService;
private AccountServiceInterface $accountService;
private AccountHistoryServiceInterface $accountHistoryService;
private ItemPresetServiceInterface $itemPresetService;
private CategoryGrid $categoryGrid;
private TagGrid $tagGrid;
private ClientGrid $clientGrid;
private CustomFieldGrid $customFieldGrid;
private FileGrid $fileGrid;
private AccountGrid $accountGrid;
private AccountHistoryGrid $accountHistoryGrid;
private ItemPresetGrid $itemPresetGrid;
public function __construct(
Application $application,
ThemeInterface $theme,
Klein $router,
Acl $acl,
RequestInterface $request,
PhpExtensionChecker $extensionChecker,
TemplateInterface $template,
BrowserAuthInterface $browser,
LayoutHelper $layoutHelper,
Helpers\TabsGridHelper $tabsGridHelper,
CategoryServiceInterface $categoryService,
TagServiceInterface $tagService,
ClientServiceInterface $clientService,
CustomFieldDefServiceInterface $customFieldDefService,
AccountFileServiceInterface $accountFileService,
AccountServiceInterface $accountService,
AccountHistoryServiceInterface $accountHistoryService,
ItemPresetServiceInterface $itemPresetService,
Helpers\Grid\CategoryGrid $categoryGrid,
Helpers\Grid\TagGrid $tagGrid,
Helpers\Grid\ClientGrid $clientGrid,
Helpers\Grid\CustomFieldGrid $customFieldGrid,
Helpers\Grid\FileGrid $fileGrid,
Helpers\Grid\AccountGrid $accountGrid,
Helpers\Grid\AccountHistoryGrid $accountHistoryGrid,
Helpers\Grid\ItemPresetGrid $itemPresetGrid
) {
$this->tabsGridHelper = $tabsGridHelper;
$this->categoryService = $categoryService;
$this->tagService = $tagService;
$this->clientService = $clientService;
$this->customFieldDefService = $customFieldDefService;
$this->accountFileService = $accountFileService;
$this->accountService = $accountService;
$this->accountHistoryService = $accountHistoryService;
$this->itemPresetService = $itemPresetService;
$this->categoryGrid = $categoryGrid;
$this->tagGrid = $tagGrid;
$this->clientGrid = $clientGrid;
$this->customFieldGrid = $customFieldGrid;
$this->fileGrid = $fileGrid;
$this->accountGrid = $accountGrid;
$this->accountHistoryGrid = $accountHistoryGrid;
$this->itemPresetGrid = $itemPresetGrid;
parent::__construct(
$application,
$theme,
$router,
$acl,
$request,
$extensionChecker,
$template,
$browser,
$layoutHelper
);
$this->checkLoggedIn();
}
/**
* @throws DependencyException
* @throws NotFoundException
* @throws ConstraintException
* @throws QueryException
*/
@@ -77,18 +156,14 @@ final class ItemManagerController extends ControllerBase
/**
* Returns a tabbed grid with items
*
* @throws DependencyException
* @throws NotFoundException
* @throws ConstraintException
* @throws QueryException
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
protected function getGridTabs(): void
{
$this->itemSearchData = new ItemSearchData();
$this->itemSearchData->setLimitCount($this->configData->getAccountCount());
$this->tabsGridHelper = $this->dic->get(TabsGridHelper::class);
if ($this->checkAccess(ActionsInterface::CATEGORY)) {
$this->tabsGridHelper->addTab($this->getCategoriesList());
}
@@ -138,68 +213,49 @@ final class ItemManagerController extends ControllerBase
/**
* Returns categories' data tab
*
* @return DataGridTab
* @throws DependencyException
* @throws NotFoundException
* @throws ConstraintException
* @throws QueryException
* @return \SP\Html\DataGrid\DataGridTab
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
protected function getCategoriesList(): DataGridTab
{
return $this->dic->get(CategoryGrid::class)
->getGrid($this->dic->get(CategoryService::class)
->search($this->itemSearchData))
->updatePager();
return $this->categoryGrid->getGrid($this->categoryService->search($this->itemSearchData))->updatePager();
}
/**
* Returns tags' data tab
*
* @return DataGridTab
* @throws DependencyException
* @throws NotFoundException
* @throws ConstraintException
* @throws QueryException
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
protected function getTagsList(): DataGridTab
{
return $this->dic->get(TagGrid::class)
->getGrid($this->dic->get(TagService::class)
->search($this->itemSearchData))
->updatePager();
return $this->tagGrid->getGrid($this->tagService->search($this->itemSearchData))->updatePager();
}
/**
* Returns clients' data tab
*
* @return DataGridTab
* @throws DependencyException
* @throws NotFoundException
* @throws ConstraintException
* @throws QueryException
*/
protected function getClientsList(): DataGridTab
{
return $this->dic->get(ClientGrid::class)
->getGrid($this->dic->get(ClientService::class)
->search($this->itemSearchData))
->updatePager();
return $this->clientGrid->getGrid($this->clientService->search($this->itemSearchData))->updatePager();
}
/**
* Returns custom fields' data tab
*
* @return DataGridTab
* @throws DependencyException
* @throws NotFoundException
* @throws ConstraintException
* @throws QueryException
*/
protected function getCustomFieldsList(): DataGridTab
{
return $this->dic->get(CustomFieldGrid::class)
->getGrid($this->dic->get(CustomFieldDefService::class)
->search($this->itemSearchData))
return $this->customFieldGrid->getGrid($this->customFieldDefService->search($this->itemSearchData))
->updatePager();
}
@@ -207,50 +263,36 @@ final class ItemManagerController extends ControllerBase
* Returns account files' data tab
*
* @return DataGridTab
* @throws DependencyException
* @throws NotFoundException
* @throws ConstraintException
* @throws QueryException
*/
protected function getAccountFilesList(): DataGridTab
{
return $this->dic->get(FileGrid::class)
->getGrid($this->dic->get(AccountFileService::class)
->search($this->itemSearchData))
->updatePager();
return $this->fileGrid->getGrid($this->accountFileService->search($this->itemSearchData))->updatePager();
}
/**
* Returns accounts' data tab
*
* @return DataGridTab
* @throws DependencyException
* @throws NotFoundException
* @throws ConstraintException
* @throws QueryException
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
protected function getAccountsList(): DataGridTab
{
return $this->dic->get(AccountGrid::class)
->getGrid($this->dic->get(AccountService::class)
->search($this->itemSearchData))
->updatePager();
return $this->accountGrid->getGrid($this->accountService->search($this->itemSearchData))->updatePager();
}
/**
* Returns accounts' history data tab
*
* @return DataGridTab
* @throws DependencyException
* @throws NotFoundException
* @throws ConstraintException
* @throws QueryException
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
protected function getAccountsHistoryList(): DataGridTab
{
return $this->dic->get(AccountHistoryGrid::class)
->getGrid($this->dic->get(AccountHistoryService::class)
->search($this->itemSearchData))
return $this->accountHistoryGrid->getGrid($this->accountHistoryService->search($this->itemSearchData))
->updatePager();
}
@@ -258,17 +300,12 @@ final class ItemManagerController extends ControllerBase
* Returns API tokens data tab
*
* @return DataGridTab
* @throws DependencyException
* @throws NotFoundException
* @throws ConstraintException
* @throws QueryException
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
protected function getItemPresetList(): DataGridTab
{
return $this->dic->get(ItemPresetGrid::class)
->getGrid($this->dic->get(ItemPresetService::class)
->search($this->itemSearchData))
->updatePager();
return $this->itemPresetGrid->getGrid($this->itemPresetService->search($this->itemSearchData))->updatePager();
}
/**
@@ -278,15 +315,4 @@ final class ItemManagerController extends ControllerBase
{
return $this->tabsGridHelper;
}
/**
* @throws AuthException
* @throws DependencyException
* @throws NotFoundException
* @throws SessionTimeout
*/
protected function initialize(): void
{
$this->checkLoggedIn();
}
}