diff --git a/lib/RoadizCoreBundle/src/EventSubscriber/AutomaticWebhookSubscriber.php b/lib/RoadizCoreBundle/src/EventSubscriber/AutomaticWebhookSubscriber.php index 0ffa1a25..fb29b2fc 100644 --- a/lib/RoadizCoreBundle/src/EventSubscriber/AutomaticWebhookSubscriber.php +++ b/lib/RoadizCoreBundle/src/EventSubscriber/AutomaticWebhookSubscriber.php @@ -35,7 +35,7 @@ public function __construct( public static function getSubscribedEvents(): array { return [ - 'workflow.node.completed' => ['onAutomaticWebhook'], + 'workflow.node.completed' => 'onAutomaticWebhook', NodeVisibilityChangedEvent::class => 'onAutomaticWebhook', NodesSourcesPreUpdatedEvent::class => 'onAutomaticWebhook', NodesSourcesDeletedEvent::class => 'onAutomaticWebhook', diff --git a/lib/RoadizCoreBundle/src/EventSubscriber/LocaleSubscriber.php b/lib/RoadizCoreBundle/src/EventSubscriber/LocaleSubscriber.php index 1796e233..607f3dfd 100644 --- a/lib/RoadizCoreBundle/src/EventSubscriber/LocaleSubscriber.php +++ b/lib/RoadizCoreBundle/src/EventSubscriber/LocaleSubscriber.php @@ -30,7 +30,7 @@ public static function getSubscribedEvents(): array { return [ // must be registered just after Symfony\Component\HttpKernel\EventListener\LocaleListener - RequestEvent::class => [['onKernelRequest', 16]], + RequestEvent::class => ['onKernelRequest', 16], ]; } diff --git a/lib/RoadizCoreBundle/src/EventSubscriber/NodeSourcePathSubscriber.php b/lib/RoadizCoreBundle/src/EventSubscriber/NodeSourcePathSubscriber.php index c7f2b9f9..0165266b 100644 --- a/lib/RoadizCoreBundle/src/EventSubscriber/NodeSourcePathSubscriber.php +++ b/lib/RoadizCoreBundle/src/EventSubscriber/NodeSourcePathSubscriber.php @@ -9,10 +9,10 @@ use RZ\Roadiz\CoreBundle\Routing\NodesSourcesUrlGenerator; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -class NodeSourcePathSubscriber implements EventSubscriberInterface +final class NodeSourcePathSubscriber implements EventSubscriberInterface { public function __construct( - protected readonly NodesSourcesPathAggregator $pathAggregator + private readonly NodesSourcesPathAggregator $pathAggregator ) { } @@ -22,7 +22,7 @@ public function __construct( public static function getSubscribedEvents(): array { return [ - NodesSourcesPathGeneratingEvent::class => [['onNodesSourcesPath', -100]], + NodesSourcesPathGeneratingEvent::class => ['onNodesSourcesPath', -100], ]; } diff --git a/lib/RoadizCoreBundle/src/EventSubscriber/NodesSourcesLinkHeaderEventSubscriber.php b/lib/RoadizCoreBundle/src/EventSubscriber/NodesSourcesLinkHeaderEventSubscriber.php index a852c6eb..a0428d69 100644 --- a/lib/RoadizCoreBundle/src/EventSubscriber/NodesSourcesLinkHeaderEventSubscriber.php +++ b/lib/RoadizCoreBundle/src/EventSubscriber/NodesSourcesLinkHeaderEventSubscriber.php @@ -14,17 +14,12 @@ use Symfony\Component\WebLink\GenericLinkProvider; use Symfony\Component\WebLink\Link; -class NodesSourcesLinkHeaderEventSubscriber implements EventSubscriberInterface +final class NodesSourcesLinkHeaderEventSubscriber implements EventSubscriberInterface { - private ManagerRegistry $managerRegistry; - private UrlGeneratorInterface $urlGenerator; - public function __construct( - ManagerRegistry $managerRegistry, - UrlGeneratorInterface $urlGenerator + private readonly ManagerRegistry $managerRegistry, + private readonly UrlGeneratorInterface $urlGenerator ) { - $this->managerRegistry = $managerRegistry; - $this->urlGenerator = $urlGenerator; } /** @@ -40,33 +35,35 @@ public static function getSubscribedEvents(): array public function onKernelView(ViewEvent $event): void { $request = $event->getRequest(); - $resources = $request->attributes->get('data', null); + $resources = $request->attributes->get('data'); $linkProvider = $request->attributes->get('_links', new GenericLinkProvider()); - if ($resources instanceof NodesSources && $linkProvider instanceof EvolvableLinkProviderInterface) { - /* - * Preview and authentication is handled at repository level. - */ - /** @var NodesSources[] $allSources */ - $allSources = $this->managerRegistry - ->getRepository(get_class($resources)) - ->findByNode($resources->getNode()); + if (!$resources instanceof NodesSources || !$linkProvider instanceof EvolvableLinkProviderInterface) { + return; + } + + /* + * Preview and authentication is handled at repository level. + */ + /** @var NodesSources[] $allSources */ + $allSources = $this->managerRegistry + ->getRepository(get_class($resources)) + ->findByNode($resources->getNode()); - foreach ($allSources as $singleSource) { - $linkProvider = $linkProvider->withLink( - (new Link( - 'alternate', - $this->urlGenerator->generate(RouteObjectInterface::OBJECT_BASED_ROUTE_NAME, [ - RouteObjectInterface::ROUTE_OBJECT => $singleSource - ]) - )) - ->withAttribute('hreflang', $singleSource->getTranslation()->getLocale()) - // Must encode translation name in base64 because headers are ASCII only - ->withAttribute('title', \base64_encode($singleSource->getTranslation()->getName())) - ->withAttribute('type', 'text/html') - ); - } - $request->attributes->set('_links', $linkProvider); + foreach ($allSources as $singleSource) { + $linkProvider = $linkProvider->withLink( + (new Link( + 'alternate', + $this->urlGenerator->generate(RouteObjectInterface::OBJECT_BASED_ROUTE_NAME, [ + RouteObjectInterface::ROUTE_OBJECT => $singleSource + ]) + )) + ->withAttribute('hreflang', $singleSource->getTranslation()->getLocale()) + // Must encode translation name in base64 because headers are ASCII only + ->withAttribute('title', \base64_encode($singleSource->getTranslation()->getName())) + ->withAttribute('type', 'text/html') + ); } + $request->attributes->set('_links', $linkProvider); } } diff --git a/lib/RoadizCoreBundle/src/EventSubscriber/SignatureSubscriber.php b/lib/RoadizCoreBundle/src/EventSubscriber/SignatureSubscriber.php index 518e73b1..68bcb97c 100644 --- a/lib/RoadizCoreBundle/src/EventSubscriber/SignatureSubscriber.php +++ b/lib/RoadizCoreBundle/src/EventSubscriber/SignatureSubscriber.php @@ -10,15 +10,11 @@ final class SignatureSubscriber implements EventSubscriberInterface { - private string $version; - private bool $debug; - private bool $hideRoadizVersion; - - public function __construct(string $cmsVersion, bool $hideRoadizVersion, bool $debug = false) - { - $this->version = $cmsVersion; - $this->debug = $debug; - $this->hideRoadizVersion = $hideRoadizVersion; + public function __construct( + private readonly string $cmsVersion, + private readonly bool $hideRoadizVersion, + private readonly bool $debug = false + ) { } /** * Filters the Response. @@ -34,8 +30,8 @@ public function onKernelResponse(ResponseEvent $event): void $response = $event->getResponse(); $response->headers->add(['X-Powered-By' => 'Roadiz CMS']); - if ($this->debug && $this->version) { - $response->headers->add(['X-Version' => $this->version]); + if ($this->debug && $this->cmsVersion) { + $response->headers->add(['X-Version' => $this->cmsVersion]); } } diff --git a/lib/RoadizCoreBundle/src/EventSubscriber/TagTimestampSubscriber.php b/lib/RoadizCoreBundle/src/EventSubscriber/TagTimestampSubscriber.php index ca59a717..86b30b43 100644 --- a/lib/RoadizCoreBundle/src/EventSubscriber/TagTimestampSubscriber.php +++ b/lib/RoadizCoreBundle/src/EventSubscriber/TagTimestampSubscriber.php @@ -22,9 +22,6 @@ public static function getSubscribedEvents(): array public function onTagUpdatedEvent(TagUpdatedEvent $event): void { - $tag = $event->getTag(); - if ($tag instanceof AbstractDateTimed) { - $tag->setUpdatedAt(new \DateTime()); - } + $event->getTag()->setUpdatedAt(new \DateTime()); } } diff --git a/lib/RoadizCoreBundle/src/EventSubscriber/TranslationSubscriber.php b/lib/RoadizCoreBundle/src/EventSubscriber/TranslationSubscriber.php index 6e773d4f..d9b85f68 100644 --- a/lib/RoadizCoreBundle/src/EventSubscriber/TranslationSubscriber.php +++ b/lib/RoadizCoreBundle/src/EventSubscriber/TranslationSubscriber.php @@ -18,13 +18,10 @@ /** * Subscribe to Translation event to clear result cache. */ -class TranslationSubscriber implements EventSubscriberInterface +final class TranslationSubscriber implements EventSubscriberInterface { - protected ManagerRegistry $managerRegistry; - - public function __construct(ManagerRegistry $managerRegistry) + public function __construct(private readonly ManagerRegistry $managerRegistry) { - $this->managerRegistry = $managerRegistry; } public static function getSubscribedEvents(): array diff --git a/lib/RoadizCoreBundle/src/EventSubscriber/UserLocaleSubscriber.php b/lib/RoadizCoreBundle/src/EventSubscriber/UserLocaleSubscriber.php index a008a6a8..5b865a5c 100644 --- a/lib/RoadizCoreBundle/src/EventSubscriber/UserLocaleSubscriber.php +++ b/lib/RoadizCoreBundle/src/EventSubscriber/UserLocaleSubscriber.php @@ -15,15 +15,10 @@ final class UserLocaleSubscriber implements EventSubscriberInterface { - private RequestStack $requestStack; - private TokenStorageInterface $tokenStorage; - public function __construct( - RequestStack $requestStack, - TokenStorageInterface $tokenStorage + private readonly RequestStack $requestStack, + private readonly TokenStorageInterface $tokenStorage ) { - $this->requestStack = $requestStack; - $this->tokenStorage = $tokenStorage; } /** @@ -34,7 +29,7 @@ public static function getSubscribedEvents(): array // must be registered after the default Locale listener return [ SecurityEvents::INTERACTIVE_LOGIN => 'onInteractiveLogin', - UserUpdatedEvent::class => [['onUserUpdated']], + UserUpdatedEvent::class => 'onUserUpdated', ]; } diff --git a/lib/RoadizCoreBundle/src/Preview/EventSubscriber/PreviewModeSubscriber.php b/lib/RoadizCoreBundle/src/Preview/EventSubscriber/PreviewModeSubscriber.php index c562e659..84b29d26 100644 --- a/lib/RoadizCoreBundle/src/Preview/EventSubscriber/PreviewModeSubscriber.php +++ b/lib/RoadizCoreBundle/src/Preview/EventSubscriber/PreviewModeSubscriber.php @@ -6,31 +6,21 @@ use RZ\Roadiz\CoreBundle\Preview\Exception\PreviewNotAllowedException; use RZ\Roadiz\CoreBundle\Preview\PreviewResolverInterface; +use Symfony\Bundle\SecurityBundle\Security; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\Event\ControllerEvent; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\KernelEvents; -use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; -use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; -use Symfony\Bundle\SecurityBundle\Security; -class PreviewModeSubscriber implements EventSubscriberInterface +final class PreviewModeSubscriber implements EventSubscriberInterface { public const QUERY_PARAM_NAME = '_preview'; - protected PreviewResolverInterface $previewResolver; - protected TokenStorageInterface $tokenStorage; - protected Security $security; - public function __construct( - PreviewResolverInterface $previewResolver, - TokenStorageInterface $tokenStorage, - Security $security + private readonly PreviewResolverInterface $previewResolver, + private readonly Security $security ) { - $this->previewResolver = $previewResolver; - $this->tokenStorage = $tokenStorage; - $this->security = $security; } /** @@ -39,7 +29,7 @@ public function __construct( public static function getSubscribedEvents(): array { return [ - KernelEvents::REQUEST => ['onKernelRequest', 9999], + KernelEvents::REQUEST => ['onKernelRequest', 2047], KernelEvents::CONTROLLER => ['onControllerMatched', 10], KernelEvents::RESPONSE => 'onResponse', ]; @@ -61,9 +51,9 @@ public function onKernelRequest(RequestEvent $event): void $request = $event->getRequest(); if ( $event->isMainRequest() && - $request->query->has(static::QUERY_PARAM_NAME) && + $request->query->has(self::QUERY_PARAM_NAME) && \in_array( - $request->query->get(static::QUERY_PARAM_NAME, 0), + $request->query->get(self::QUERY_PARAM_NAME, 0), ['true', true, '1', 1, 'on', 'yes', 'y'], true )