Skip to content

Commit

Permalink
[TASK] Removed Abstract class and moved functions to Traits
Browse files Browse the repository at this point in the history
  • Loading branch information
hojalatheef committed Jan 9, 2025
1 parent bd2ee0a commit ede4f07
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 63 deletions.
61 changes: 0 additions & 61 deletions Classes/Controller/AbstractController.php

This file was deleted.

10 changes: 9 additions & 1 deletion Classes/Controller/CompanyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
use JWeiland\Yellowpages2\Domain\Repository\DistrictRepository;
use JWeiland\Yellowpages2\Domain\Repository\FeUserRepository;
use JWeiland\Yellowpages2\Helper\MailHelper;
use JWeiland\Yellowpages2\Traits\PostProcessControllerActionTrait;
use JWeiland\Yellowpages2\Traits\PostProcessFluidVariablesTrait;
use JWeiland\Yellowpages2\Traits\PreProcessControllerActionTrait;
use JWeiland\Yellowpages2\Utility\CacheUtility;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Core\Context\Context;
Expand All @@ -27,13 +30,18 @@
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Annotation\IgnoreValidation;
use TYPO3\CMS\Extbase\Annotation\Validate;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;

/**
* Controller to list, show and search for companies
*/
class CompanyController extends AbstractController
class CompanyController extends ActionController
{
use PostProcessFluidVariablesTrait;
use PostProcessControllerActionTrait;
use PreProcessControllerActionTrait;

public function __construct(
private readonly Context $context,
private readonly CompanyRepository $companyRepository,
Expand Down
10 changes: 9 additions & 1 deletion Classes/Controller/MapController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,24 @@
use JWeiland\Yellowpages2\Domain\Model\Company;
use JWeiland\Yellowpages2\Domain\Repository\CompanyRepository;
use JWeiland\Yellowpages2\Helper\MailHelper;
use JWeiland\Yellowpages2\Traits\PostProcessControllerActionTrait;
use JWeiland\Yellowpages2\Traits\PostProcessFluidVariablesTrait;
use JWeiland\Yellowpages2\Traits\PreProcessControllerActionTrait;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;

/**
* Controller to show and save PoiCollections on a map
*/
class MapController extends AbstractController
class MapController extends ActionController
{
use PostProcessFluidVariablesTrait;
use PostProcessControllerActionTrait;
use PreProcessControllerActionTrait;

protected CompanyRepository $companyRepository;

protected PersistenceManagerInterface $persistenceManager;
Expand Down
30 changes: 30 additions & 0 deletions Classes/Traits/PostProcessControllerActionTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

/*
* This file is part of the package jweiland/yellowpages2.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

namespace JWeiland\Yellowpages2\Traits;

use JWeiland\Yellowpages2\Domain\Model\Company;
use JWeiland\Yellowpages2\Event\PostProcessControllerActionEvent;

trait PostProcessControllerActionTrait
{
protected function postProcessControllerAction(?Company $company): void
{
$this->eventDispatcher->dispatch(
new PostProcessControllerActionEvent(
$this,
$company,
$this->settings,
$this->request,
),
);
}
}
30 changes: 30 additions & 0 deletions Classes/Traits/PostProcessFluidVariablesTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

/*
* This file is part of the package jweiland/yellowpages2.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

namespace JWeiland\Yellowpages2\Traits;

use JWeiland\Yellowpages2\Event\PostProcessFluidVariablesEvent;

trait PostProcessFluidVariablesTrait
{
protected function postProcessAndAssignFluidVariables(array $variables = []): void
{
$event = $this->eventDispatcher->dispatch(
new PostProcessFluidVariablesEvent(
$this->request,
$this->settings,
$variables,
),
);

$this->view->assignMultiple($event->getFluidVariables());
}
}
28 changes: 28 additions & 0 deletions Classes/Traits/PreProcessControllerActionTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

/*
* This file is part of the package jweiland/yellowpages2.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

namespace JWeiland\Yellowpages2\Traits;

use JWeiland\Yellowpages2\Event\PreProcessControllerActionEvent;

trait PreProcessControllerActionTrait
{
protected function preProcessControllerAction(): void
{
$this->eventDispatcher->dispatch(
new PreProcessControllerActionEvent(
$this->request,
$this->arguments,
$this->settings,
),
);
}
}

0 comments on commit ede4f07

Please sign in to comment.