Skip to content

Commit

Permalink
refactor: Some constructor args refactoring, remove direct dependency…
Browse files Browse the repository at this point in the history
… on KernelInterface
  • Loading branch information
roadiz-ci committed Mar 8, 2024
1 parent aa87cc9 commit b113f19
Show file tree
Hide file tree
Showing 27 changed files with 160 additions and 369 deletions.
6 changes: 1 addition & 5 deletions src/Controllers/Attributes/AttributeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,15 @@

class AttributeController extends AbstractAdminWithBulkController
{
private AttributeImporter $attributeImporter;

public function __construct(
AttributeImporter $attributeImporter,
private readonly AttributeImporter $attributeImporter,
FormFactoryInterface $formFactory,
SerializerInterface $serializer,
UrlGeneratorInterface $urlGenerator
) {
parent::__construct($formFactory, $serializer, $urlGenerator);
$this->attributeImporter = $attributeImporter;
}


/**
* @inheritDoc
*/
Expand Down
9 changes: 2 additions & 7 deletions src/Controllers/CacheController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,10 @@

final class CacheController extends RozierApp
{
private LoggerInterface $logger;
private CacheClearerInterface $cacheClearer;

public function __construct(
CacheClearerInterface $cacheClearer,
LoggerInterface $logger
private readonly CacheClearerInterface $cacheClearer,
private readonly LoggerInterface $logger
) {
$this->logger = $logger;
$this->cacheClearer = $cacheClearer;
}

public function deleteDoctrineCache(Request $request): Response
Expand Down
8 changes: 1 addition & 7 deletions src/Controllers/CustomForms/CustomFormsUtilsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,8 @@

class CustomFormsUtilsController extends RozierApp
{
private CustomFormAnswerSerializer $customFormAnswerSerializer;

/**
* @param CustomFormAnswerSerializer $customFormAnswerSerializer
*/
public function __construct(CustomFormAnswerSerializer $customFormAnswerSerializer)
public function __construct(private readonly CustomFormAnswerSerializer $customFormAnswerSerializer)
{
$this->customFormAnswerSerializer = $customFormAnswerSerializer;
}

/**
Expand Down
29 changes: 8 additions & 21 deletions src/Controllers/Documents/DocumentTranslationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use RZ\Roadiz\CoreBundle\Entity\Translation;
use RZ\Roadiz\CoreBundle\Event\Document\DocumentTranslationUpdatedEvent;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
Expand All @@ -34,7 +35,7 @@ class DocumentTranslationsController extends RozierApp
* @return Response
* @throws RuntimeError
*/
public function editAction(Request $request, int $documentId, ?int $translationId = null)
public function editAction(Request $request, int $documentId, ?int $translationId = null): Response
{
$this->denyAccessUnlessGranted('ROLE_ACCESS_DOCUMENTS');

Expand Down Expand Up @@ -117,14 +118,10 @@ public function editAction(Request $request, int $documentId, ?int $translationI
throw new ResourceNotFoundException();
}

/**
* @param Document $document
* @param TranslationInterface $translation
*
* @return DocumentTranslation
*/
protected function createDocumentTranslation(Document $document, TranslationInterface $translation)
{
protected function createDocumentTranslation(
Document $document,
TranslationInterface $translation
): DocumentTranslation {
$dt = new DocumentTranslation();
$dt->setDocument($document);
$dt->setTranslation($translation);
Expand All @@ -144,7 +141,7 @@ protected function createDocumentTranslation(Document $document, TranslationInte
* @return Response
* @throws RuntimeError
*/
public function deleteAction(Request $request, int $documentId, int $translationId)
public function deleteAction(Request $request, int $documentId, int $translationId): Response
{
$this->denyAccessUnlessGranted('ROLE_ACCESS_DOCUMENTS_DELETE');

Expand Down Expand Up @@ -201,12 +198,7 @@ public function deleteAction(Request $request, int $documentId, int $translation
throw new ResourceNotFoundException();
}

/**
* @param DocumentTranslation $doc
*
* @return \Symfony\Component\Form\FormInterface
*/
private function buildDeleteForm(DocumentTranslation $doc)
private function buildDeleteForm(DocumentTranslation $doc): FormInterface
{
$defaults = [
'documentTranslationId' => $doc->getId(),
Expand Down Expand Up @@ -240,11 +232,6 @@ protected function onPostUpdate(PersistableInterface $entity, Request $request):
}
}

/**
* @param PersistableInterface $entity
*
* @return Response
*/
protected function getPostUpdateRedirection(PersistableInterface $entity): ?Response
{
if (
Expand Down
49 changes: 12 additions & 37 deletions src/Controllers/Documents/DocumentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,6 @@

class DocumentsController extends RozierApp
{
private array $documentPlatforms;
private DocumentFactory $documentFactory;
private HandlerFactoryInterface $handlerFactory;
private LoggerInterface $logger;
private RandomImageFinder $randomImageFinder;
private RendererInterface $renderer;
private DocumentUrlGeneratorInterface $documentUrlGenerator;
private UrlGeneratorInterface $urlGenerator;
private FilesystemOperator $documentsStorage;
private ?string $googleServerId;
private ?string $soundcloudClientId;

protected array $thumbnailFormat = [
'quality' => 50,
'fit' => '128x128',
Expand All @@ -81,34 +69,21 @@ class DocumentsController extends RozierApp
'controls' => false,
'loading' => 'lazy',
];
private EmbedFinderFactory $embedFinderFactory;

public function __construct(
array $documentPlatforms,
FilesystemOperator $documentsStorage,
HandlerFactoryInterface $handlerFactory,
LoggerInterface $logger,
RandomImageFinder $randomImageFinder,
DocumentFactory $documentFactory,
RendererInterface $renderer,
DocumentUrlGeneratorInterface $documentUrlGenerator,
UrlGeneratorInterface $urlGenerator,
EmbedFinderFactory $embedFinderFactory,
?string $googleServerId = null,
?string $soundcloudClientId = null
private readonly array $documentPlatforms,
private readonly FilesystemOperator $documentsStorage,
private readonly HandlerFactoryInterface $handlerFactory,
private readonly LoggerInterface $logger,
private readonly RandomImageFinder $randomImageFinder,
private readonly DocumentFactory $documentFactory,
private readonly RendererInterface $renderer,
private readonly DocumentUrlGeneratorInterface $documentUrlGenerator,
private readonly UrlGeneratorInterface $urlGenerator,
private readonly EmbedFinderFactory $embedFinderFactory,
private readonly ?string $googleServerId = null,
private readonly ?string $soundcloudClientId = null
) {
$this->documentPlatforms = $documentPlatforms;
$this->handlerFactory = $handlerFactory;
$this->logger = $logger;
$this->randomImageFinder = $randomImageFinder;
$this->documentFactory = $documentFactory;
$this->renderer = $renderer;
$this->documentUrlGenerator = $documentUrlGenerator;
$this->urlGenerator = $urlGenerator;
$this->googleServerId = $googleServerId;
$this->soundcloudClientId = $soundcloudClientId;
$this->documentsStorage = $documentsStorage;
$this->embedFinderFactory = $embedFinderFactory;
}

/**
Expand Down
5 changes: 1 addition & 4 deletions src/Controllers/FoldersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@

class FoldersController extends RozierApp
{
private DocumentArchiver $documentArchiver;

public function __construct(DocumentArchiver $documentArchiver)
public function __construct(private readonly DocumentArchiver $documentArchiver)
{
$this->documentArchiver = $documentArchiver;
}

public function indexAction(Request $request): Response
Expand Down
15 changes: 4 additions & 11 deletions src/Controllers/GroupsUtilsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,10 @@

class GroupsUtilsController extends RozierApp
{
private SerializerInterface $serializer;
private GroupsImporter $groupsImporter;

/**
* @param SerializerInterface $serializer
* @param GroupsImporter $groupsImporter
*/
public function __construct(SerializerInterface $serializer, GroupsImporter $groupsImporter)
{
$this->serializer = $serializer;
$this->groupsImporter = $groupsImporter;
public function __construct(
private readonly SerializerInterface $serializer,
private readonly GroupsImporter $groupsImporter
) {
}

/**
Expand Down
8 changes: 3 additions & 5 deletions src/Controllers/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ public function imageAction(Request $request): Response
'quality' => 80,
'sharpen' => 5,
]);
$response->setData([
return $response->setData([
'url' => $this->documentUrlGenerator->getUrl()
]);
return $response;
}
}

Expand All @@ -54,9 +53,8 @@ public function imageAction(Request $request): Response
if (null !== $feed) {
$url = $feed['url'] ?? $feed['urls']['regular'] ?? $feed['urls']['full'] ?? $feed['urls']['raw'] ?? null;
}
$response->setData([
'url' => '/themes/Rozier/static/assets/img/default_login.jpg'
return $response->setData([
'url' => $url ?? '/themes/Rozier/static/assets/img/default_login.jpg'
]);
return $response;
}
}
20 changes: 8 additions & 12 deletions src/Controllers/NodeTypeFieldsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Symfony\Component\Form\FormError;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
Expand All @@ -22,13 +21,10 @@

class NodeTypeFieldsController extends RozierApp
{
private MessageBusInterface $messageBus;
private KernelInterface $kernel;

public function __construct(KernelInterface $kernel, MessageBusInterface $messageBus)
{
$this->messageBus = $messageBus;
$this->kernel = $kernel;
public function __construct(
private readonly bool $allowNodeTypeEdition,
private readonly MessageBusInterface $messageBus
) {
}

/**
Expand Down Expand Up @@ -82,7 +78,7 @@ public function editAction(Request $request, int $nodeTypeFieldId): Response
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
if (!$this->kernel->isDebug()) {
if (!$this->allowNodeTypeEdition) {
$form->addError(new FormError('You cannot edit node-type fields in production.'));
} else {
$this->em()->flush();
Expand Down Expand Up @@ -138,12 +134,12 @@ public function addAction(Request $request, int $nodeTypeId): Response
$this->assignation['field'] = $field;

$form = $this->createForm(NodeTypeFieldType::class, $field, [
'disabled' => !$this->kernel->isDebug()
'disabled' => !$this->allowNodeTypeEdition
]);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
if (!$this->kernel->isDebug()) {
if (!$this->allowNodeTypeEdition) {
$form->addError(new FormError('You cannot add node-type fields in production.'));
} else {
try {
Expand Down Expand Up @@ -198,7 +194,7 @@ public function deleteAction(Request $request, int $nodeTypeFieldId): Response
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
if (!$this->kernel->isDebug()) {
if (!$this->allowNodeTypeEdition) {
$form->addError(new FormError('You cannot delete node-type fields in production.'));
} else {
/** @var NodeType $nodeType */
Expand Down
18 changes: 7 additions & 11 deletions src/Controllers/NodeTypes/NodeTypesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Symfony\Component\Form\FormError;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\MessageBusInterface;
use Themes\Rozier\Forms\NodeTypeType;
Expand All @@ -22,13 +21,10 @@

class NodeTypesController extends RozierApp
{
private MessageBusInterface $messageBus;
private KernelInterface $kernel;

public function __construct(KernelInterface $kernel, MessageBusInterface $messageBus)
{
$this->messageBus = $messageBus;
$this->kernel = $kernel;
public function __construct(
private readonly bool $allowNodeTypeEdition,
private readonly MessageBusInterface $messageBus
) {
}

public function indexAction(Request $request): Response
Expand Down Expand Up @@ -112,12 +108,12 @@ public function addAction(Request $request): Response
$nodeType = new NodeType();

$form = $this->createForm(NodeTypeType::class, $nodeType, [
'disabled' => !$this->kernel->isDebug()
'disabled' => !$this->allowNodeTypeEdition
]);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
if (!$this->kernel->isDebug()) {
if (!$this->allowNodeTypeEdition) {
$form->addError(new FormError('You cannot create a node-type in production mode.'));
} else {
try {
Expand Down Expand Up @@ -166,7 +162,7 @@ public function deleteAction(Request $request, int $nodeTypeId): Response
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
if (!$this->kernel->isDebug()) {
if (!$this->allowNodeTypeEdition) {
$form->addError(new FormError('You cannot delete a node-type in production mode.'));
} else {
$this->messageBus->dispatch(new Envelope(new DeleteNodeTypeMessage($nodeType->getId())));
Expand Down
Loading

0 comments on commit b113f19

Please sign in to comment.