From 15a3e199b23a4410b301265d742f8c30c0ac2a4f Mon Sep 17 00:00:00 2001 From: Maximilian Graf Schimmelmann Date: Thu, 4 Jan 2024 14:49:31 +0100 Subject: [PATCH 1/6] Add Interface and replaced types in injected classes. --- src/ArgumentResolver/AdminContextResolver.php | 5 +++-- src/ArgumentResolver/BatchActionDtoResolver.php | 5 +++-- src/EventListener/CrudResponseListener.php | 3 ++- src/EventListener/ExceptionListener.php | 3 ++- src/Factory/ActionFactory.php | 3 ++- src/Factory/FieldFactory.php | 3 ++- src/Factory/FilterFactory.php | 3 ++- src/Factory/MenuFactory.php | 3 ++- src/Factory/PaginatorFactory.php | 3 ++- .../Configurator/CommonPostConfigurator.php | 3 ++- src/Form/Extension/EaCrudFormTypeExtension.php | 3 ++- src/Inspector/DataCollector.php | 3 ++- src/Menu/MenuItemMatcher.php | 3 ++- src/Orm/EntityRepository.php | 3 ++- src/Provider/AdminContextProvider.php | 17 +++++------------ src/Provider/AdminContextProviderInterface.php | 16 ++++++++++++++++ src/Provider/FieldProvider.php | 2 +- src/Router/AdminUrlGenerator.php | 3 ++- src/Security/SecurityVoter.php | 3 ++- src/Twig/EasyAdminTwigExtension.php | 3 ++- 20 files changed, 58 insertions(+), 32 deletions(-) create mode 100644 src/Provider/AdminContextProviderInterface.php diff --git a/src/ArgumentResolver/AdminContextResolver.php b/src/ArgumentResolver/AdminContextResolver.php index 810e1fcaed..65c34e1114 100644 --- a/src/ArgumentResolver/AdminContextResolver.php +++ b/src/ArgumentResolver/AdminContextResolver.php @@ -4,6 +4,7 @@ use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext; use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; +use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProviderInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface; use Symfony\Component\HttpKernel\Controller\ValueResolverInterface; @@ -17,7 +18,7 @@ final class AdminContextResolver implements ValueResolverInterface { private AdminContextProvider $adminContextProvider; - public function __construct(AdminContextProvider $adminContextProvider) + public function __construct(AdminContextProviderInterface $adminContextProvider) { $this->adminContextProvider = $adminContextProvider; } @@ -36,7 +37,7 @@ final class AdminContextResolver implements ArgumentValueResolverInterface { private AdminContextProvider $adminContextProvider; - public function __construct(AdminContextProvider $adminContextProvider) + public function __construct(AdminContextProviderInterface $adminContextProvider) { $this->adminContextProvider = $adminContextProvider; } diff --git a/src/ArgumentResolver/BatchActionDtoResolver.php b/src/ArgumentResolver/BatchActionDtoResolver.php index 61a4c1e01e..2eae340ccb 100644 --- a/src/ArgumentResolver/BatchActionDtoResolver.php +++ b/src/ArgumentResolver/BatchActionDtoResolver.php @@ -5,6 +5,7 @@ use EasyCorp\Bundle\EasyAdminBundle\Config\Option\EA; use EasyCorp\Bundle\EasyAdminBundle\Dto\BatchActionDto; use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; +use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProviderInterface; use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGeneratorInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface; @@ -20,7 +21,7 @@ final class BatchActionDtoResolver implements ValueResolverInterface private AdminContextProvider $adminContextProvider; private AdminUrlGeneratorInterface $adminUrlGenerator; - public function __construct(AdminContextProvider $adminContextProvider, AdminUrlGeneratorInterface $adminUrlGenerator) + public function __construct(AdminContextProviderInterface $adminContextProvider, AdminUrlGeneratorInterface $adminUrlGenerator) { $this->adminContextProvider = $adminContextProvider; $this->adminUrlGenerator = $adminUrlGenerator; @@ -56,7 +57,7 @@ final class BatchActionDtoResolver implements ArgumentValueResolverInterface private AdminContextProvider $adminContextProvider; private AdminUrlGeneratorInterface $adminUrlGenerator; - public function __construct(AdminContextProvider $adminContextProvider, AdminUrlGeneratorInterface $adminUrlGenerator) + public function __construct(AdminContextProviderInterface $adminContextProvider, AdminUrlGeneratorInterface $adminUrlGenerator) { $this->adminContextProvider = $adminContextProvider; $this->adminUrlGenerator = $adminUrlGenerator; diff --git a/src/EventListener/CrudResponseListener.php b/src/EventListener/CrudResponseListener.php index 0afaeff968..519837760e 100644 --- a/src/EventListener/CrudResponseListener.php +++ b/src/EventListener/CrudResponseListener.php @@ -4,6 +4,7 @@ use EasyCorp\Bundle\EasyAdminBundle\Config\KeyValueStore; use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; +use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProviderInterface; use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Event\ViewEvent; @@ -17,7 +18,7 @@ final class CrudResponseListener private AdminContextProvider $adminContextProvider; private Environment $twig; - public function __construct(AdminContextProvider $adminContextProvider, Environment $twig) + public function __construct(AdminContextProviderInterface $adminContextProvider, Environment $twig) { $this->adminContextProvider = $adminContextProvider; $this->twig = $twig; diff --git a/src/EventListener/ExceptionListener.php b/src/EventListener/ExceptionListener.php index 6bb54d0d22..af7b91c259 100644 --- a/src/EventListener/ExceptionListener.php +++ b/src/EventListener/ExceptionListener.php @@ -5,6 +5,7 @@ use EasyCorp\Bundle\EasyAdminBundle\Exception\BaseException; use EasyCorp\Bundle\EasyAdminBundle\Exception\FlattenException; use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; +use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProviderInterface; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Event\ExceptionEvent; use Twig\Environment; @@ -25,7 +26,7 @@ final class ExceptionListener private AdminContextProvider $adminContextProvider; private Environment $twig; - public function __construct(bool $kernelDebug, AdminContextProvider $adminContextProvider, Environment $twig) + public function __construct(bool $kernelDebug, AdminContextProviderInterface $adminContextProvider, Environment $twig) { $this->kernelDebug = $kernelDebug; $this->adminContextProvider = $adminContextProvider; diff --git a/src/Factory/ActionFactory.php b/src/Factory/ActionFactory.php index c994567772..a8065f0026 100644 --- a/src/Factory/ActionFactory.php +++ b/src/Factory/ActionFactory.php @@ -10,6 +10,7 @@ use EasyCorp\Bundle\EasyAdminBundle\Dto\ActionDto; use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto; use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; +use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProviderInterface; use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGeneratorInterface; use EasyCorp\Bundle\EasyAdminBundle\Security\Permission; use EasyCorp\Bundle\EasyAdminBundle\Translation\TranslatableMessageBuilder; @@ -29,7 +30,7 @@ final class ActionFactory private AdminUrlGeneratorInterface $adminUrlGenerator; private ?CsrfTokenManagerInterface $csrfTokenManager; - public function __construct(AdminContextProvider $adminContextProvider, AuthorizationCheckerInterface $authChecker, AdminUrlGeneratorInterface $adminUrlGenerator, ?CsrfTokenManagerInterface $csrfTokenManager = null) + public function __construct(AdminContextProviderInterface $adminContextProvider, AuthorizationCheckerInterface $authChecker, AdminUrlGeneratorInterface $adminUrlGenerator, ?CsrfTokenManagerInterface $csrfTokenManager = null) { $this->adminContextProvider = $adminContextProvider; $this->authChecker = $authChecker; diff --git a/src/Factory/FieldFactory.php b/src/Factory/FieldFactory.php index d6375beb70..2dc74e8ba1 100644 --- a/src/Factory/FieldFactory.php +++ b/src/Factory/FieldFactory.php @@ -20,6 +20,7 @@ use EasyCorp\Bundle\EasyAdminBundle\Field\TimeField; use EasyCorp\Bundle\EasyAdminBundle\Form\Type\EaFormRowType; use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; +use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProviderInterface; use EasyCorp\Bundle\EasyAdminBundle\Security\Permission; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; @@ -60,7 +61,7 @@ final class FieldFactory private iterable $fieldConfigurators; private FormLayoutFactory $fieldLayoutFactory; - public function __construct(AdminContextProvider $adminContextProvider, AuthorizationCheckerInterface $authorizationChecker, iterable $fieldConfigurators, FormLayoutFactory $fieldLayoutFactory) + public function __construct(AdminContextProviderInterface $adminContextProvider, AuthorizationCheckerInterface $authorizationChecker, iterable $fieldConfigurators, FormLayoutFactory $fieldLayoutFactory) { $this->adminContextProvider = $adminContextProvider; $this->authorizationChecker = $authorizationChecker; diff --git a/src/Factory/FilterFactory.php b/src/Factory/FilterFactory.php index 4db429c7eb..7e477a572f 100644 --- a/src/Factory/FilterFactory.php +++ b/src/Factory/FilterFactory.php @@ -16,6 +16,7 @@ use EasyCorp\Bundle\EasyAdminBundle\Filter\NumericFilter; use EasyCorp\Bundle\EasyAdminBundle\Filter\TextFilter; use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; +use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProviderInterface; /** * @author Yonel Ceruto @@ -52,7 +53,7 @@ final class FilterFactory Types::TEXT => TextFilter::class, ]; - public function __construct(AdminContextProvider $adminContextProvider, iterable $filterConfigurators) + public function __construct(AdminContextProviderInterface $adminContextProvider, iterable $filterConfigurators) { $this->adminContextProvider = $adminContextProvider; $this->filterConfigurators = $filterConfigurators; diff --git a/src/Factory/MenuFactory.php b/src/Factory/MenuFactory.php index e099b6b129..a33c80fcc4 100644 --- a/src/Factory/MenuFactory.php +++ b/src/Factory/MenuFactory.php @@ -12,6 +12,7 @@ use EasyCorp\Bundle\EasyAdminBundle\Dto\MenuItemDto; use EasyCorp\Bundle\EasyAdminBundle\Dto\UserMenuDto; use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; +use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProviderInterface; use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGeneratorInterface; use EasyCorp\Bundle\EasyAdminBundle\Security\Permission; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; @@ -30,7 +31,7 @@ final class MenuFactory implements MenuFactoryInterface private AdminUrlGeneratorInterface $adminUrlGenerator; private MenuItemMatcherInterface $menuItemMatcher; - public function __construct(AdminContextProvider $adminContextProvider, AuthorizationCheckerInterface $authChecker, LogoutUrlGenerator $logoutUrlGenerator, AdminUrlGeneratorInterface $adminUrlGenerator, MenuItemMatcherInterface $menuItemMatcher) + public function __construct(AdminContextProviderInterface $adminContextProvider, AuthorizationCheckerInterface $authChecker, LogoutUrlGenerator $logoutUrlGenerator, AdminUrlGeneratorInterface $adminUrlGenerator, MenuItemMatcherInterface $menuItemMatcher) { $this->adminContextProvider = $adminContextProvider; $this->authChecker = $authChecker; diff --git a/src/Factory/PaginatorFactory.php b/src/Factory/PaginatorFactory.php index df07310e2b..80cbd3322b 100644 --- a/src/Factory/PaginatorFactory.php +++ b/src/Factory/PaginatorFactory.php @@ -5,6 +5,7 @@ use Doctrine\ORM\QueryBuilder; use EasyCorp\Bundle\EasyAdminBundle\Contracts\Orm\EntityPaginatorInterface; use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; +use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProviderInterface; /** * @author Javier Eguiluz @@ -14,7 +15,7 @@ final class PaginatorFactory private AdminContextProvider $adminContextProvider; private EntityPaginatorInterface $entityPaginator; - public function __construct(AdminContextProvider $adminContextProvider, EntityPaginatorInterface $entityPaginator) + public function __construct(AdminContextProviderInterface $adminContextProvider, EntityPaginatorInterface $entityPaginator) { $this->adminContextProvider = $adminContextProvider; $this->entityPaginator = $entityPaginator; diff --git a/src/Field/Configurator/CommonPostConfigurator.php b/src/Field/Configurator/CommonPostConfigurator.php index 532b236e9e..7a876fdc6b 100644 --- a/src/Field/Configurator/CommonPostConfigurator.php +++ b/src/Field/Configurator/CommonPostConfigurator.php @@ -8,6 +8,7 @@ use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto; use EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto; use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; +use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProviderInterface; use function Symfony\Component\String\u; use Twig\Markup; @@ -19,7 +20,7 @@ final class CommonPostConfigurator implements FieldConfiguratorInterface private AdminContextProvider $adminContextProvider; private string $charset; - public function __construct(AdminContextProvider $adminContextProvider, string $charset) + public function __construct(AdminContextProviderInterface $adminContextProvider, string $charset) { $this->adminContextProvider = $adminContextProvider; $this->charset = $charset; diff --git a/src/Form/Extension/EaCrudFormTypeExtension.php b/src/Form/Extension/EaCrudFormTypeExtension.php index ac23fe22f5..3e7885c0d4 100644 --- a/src/Form/Extension/EaCrudFormTypeExtension.php +++ b/src/Form/Extension/EaCrudFormTypeExtension.php @@ -4,6 +4,7 @@ use EasyCorp\Bundle\EasyAdminBundle\Dto\FormVarsDto; use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; +use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProviderInterface; use Symfony\Component\Form\AbstractTypeExtension; use Symfony\Component\Form\Extension\Core\Type\FormType; use Symfony\Component\Form\FormInterface; @@ -20,7 +21,7 @@ class EaCrudFormTypeExtension extends AbstractTypeExtension { private AdminContextProvider $adminContextProvider; - public function __construct(AdminContextProvider $adminContextProvider) + public function __construct(AdminContextProviderInterface $adminContextProvider) { $this->adminContextProvider = $adminContextProvider; } diff --git a/src/Inspector/DataCollector.php b/src/Inspector/DataCollector.php index f93fa94bb9..8d931265c9 100644 --- a/src/Inspector/DataCollector.php +++ b/src/Inspector/DataCollector.php @@ -5,6 +5,7 @@ use EasyCorp\Bundle\EasyAdminBundle\Config\Option\EA; use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext; use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; +use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProviderInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\DataCollector\DataCollector as BaseDataCollector; @@ -19,7 +20,7 @@ class DataCollector extends BaseDataCollector { private AdminContextProvider $adminContextProvider; - public function __construct(AdminContextProvider $adminContextProvider) + public function __construct(AdminContextProviderInterface $adminContextProvider) { $this->adminContextProvider = $adminContextProvider; } diff --git a/src/Menu/MenuItemMatcher.php b/src/Menu/MenuItemMatcher.php index f57b2d3500..b13d7cf50a 100644 --- a/src/Menu/MenuItemMatcher.php +++ b/src/Menu/MenuItemMatcher.php @@ -7,13 +7,14 @@ use EasyCorp\Bundle\EasyAdminBundle\Contracts\Menu\MenuItemMatcherInterface; use EasyCorp\Bundle\EasyAdminBundle\Dto\MenuItemDto; use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; +use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProviderInterface; /** * @author Javier Eguiluz */ class MenuItemMatcher implements MenuItemMatcherInterface { - public function __construct(private AdminContextProvider $adminContextProvider) + public function __construct(private AdminContextProviderInterface $adminContextProvider) { } diff --git a/src/Orm/EntityRepository.php b/src/Orm/EntityRepository.php index 4dc6ae3c47..a6f6ab598e 100644 --- a/src/Orm/EntityRepository.php +++ b/src/Orm/EntityRepository.php @@ -20,6 +20,7 @@ use EasyCorp\Bundle\EasyAdminBundle\Factory\FormFactory; use EasyCorp\Bundle\EasyAdminBundle\Form\Type\ComparisonType; use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; +use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProviderInterface; use Symfony\Component\Uid\Ulid; use Symfony\Component\Uid\Uuid; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; @@ -35,7 +36,7 @@ final class EntityRepository implements EntityRepositoryInterface private FormFactory $formFactory; private EventDispatcherInterface $eventDispatcher; - public function __construct(AdminContextProvider $adminContextProvider, ManagerRegistry $doctrine, EntityFactory $entityFactory, FormFactory $formFactory, EventDispatcherInterface $eventDispatcher) + public function __construct(AdminContextProviderInterface $adminContextProvider, ManagerRegistry $doctrine, EntityFactory $entityFactory, FormFactory $formFactory, EventDispatcherInterface $eventDispatcher) { $this->adminContextProvider = $adminContextProvider; $this->doctrine = $doctrine; diff --git a/src/Provider/AdminContextProvider.php b/src/Provider/AdminContextProvider.php index 9111811277..6ddab55649 100644 --- a/src/Provider/AdminContextProvider.php +++ b/src/Provider/AdminContextProvider.php @@ -7,23 +7,16 @@ use Symfony\Component\HttpFoundation\RequestStack; /** - * Inject this in services that need to get the admin context object. - * * @author Javier Eguiluz */ -final class AdminContextProvider +final class AdminContextProvider implements AdminContextProviderInterface { - private RequestStack $requestStack; - - public function __construct(RequestStack $requestStack) - { - $this->requestStack = $requestStack; - } + public function __construct( + private RequestStack $requestStack + ) {} public function getContext(): ?AdminContext { - $currentRequest = $this->requestStack->getCurrentRequest(); - - return null !== $currentRequest ? $currentRequest->get(EA::CONTEXT_REQUEST_ATTRIBUTE) : null; + return $this->requestStack->getCurrentRequest()?->get(EA::CONTEXT_REQUEST_ATTRIBUTE); } } diff --git a/src/Provider/AdminContextProviderInterface.php b/src/Provider/AdminContextProviderInterface.php new file mode 100644 index 0000000000..e40e82bfb9 --- /dev/null +++ b/src/Provider/AdminContextProviderInterface.php @@ -0,0 +1,16 @@ + + */ +interface AdminContextProviderInterface +{ + public function getContext(): ?AdminContext; +} diff --git a/src/Provider/FieldProvider.php b/src/Provider/FieldProvider.php index fe31bbc23f..5e4300cde6 100644 --- a/src/Provider/FieldProvider.php +++ b/src/Provider/FieldProvider.php @@ -13,7 +13,7 @@ final class FieldProvider { private AdminContextProvider $adminContextProvider; - public function __construct(AdminContextProvider $adminContextProvider) + public function __construct(AdminContextProviderInterface $adminContextProvider) { $this->adminContextProvider = $adminContextProvider; } diff --git a/src/Router/AdminUrlGenerator.php b/src/Router/AdminUrlGenerator.php index 98db7ff08f..79978fb6db 100644 --- a/src/Router/AdminUrlGenerator.php +++ b/src/Router/AdminUrlGenerator.php @@ -7,6 +7,7 @@ use EasyCorp\Bundle\EasyAdminBundle\Contracts\Controller\DashboardControllerInterface; use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController; use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; +use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProviderInterface; use EasyCorp\Bundle\EasyAdminBundle\Registry\DashboardControllerRegistry; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; @@ -25,7 +26,7 @@ final class AdminUrlGenerator implements AdminUrlGeneratorInterface private ?string $currentPageReferrer = null; private ?string $customPageReferrer = null; - public function __construct(AdminContextProvider $adminContextProvider, UrlGeneratorInterface $urlGenerator, DashboardControllerRegistry $dashboardControllerRegistry) + public function __construct(AdminContextProviderInterface $adminContextProvider, UrlGeneratorInterface $urlGenerator, DashboardControllerRegistry $dashboardControllerRegistry) { $this->adminContextProvider = $adminContextProvider; $this->urlGenerator = $urlGenerator; diff --git a/src/Security/SecurityVoter.php b/src/Security/SecurityVoter.php index e22eea05ea..3c10e33db8 100644 --- a/src/Security/SecurityVoter.php +++ b/src/Security/SecurityVoter.php @@ -8,6 +8,7 @@ use EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto; use EasyCorp\Bundle\EasyAdminBundle\Dto\MenuItemDto; use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; +use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProviderInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; use Symfony\Component\Security\Core\Authorization\Voter\Voter; @@ -20,7 +21,7 @@ final class SecurityVoter extends Voter private AuthorizationCheckerInterface $authorizationChecker; private AdminContextProvider $adminContextProvider; - public function __construct(AuthorizationCheckerInterface $authorizationChecker, AdminContextProvider $adminContextProvider) + public function __construct(AuthorizationCheckerInterface $authorizationChecker, AdminContextProviderInterface $adminContextProvider) { $this->authorizationChecker = $authorizationChecker; $this->adminContextProvider = $adminContextProvider; diff --git a/src/Twig/EasyAdminTwigExtension.php b/src/Twig/EasyAdminTwigExtension.php index 816fbeb91c..16434a50c1 100644 --- a/src/Twig/EasyAdminTwigExtension.php +++ b/src/Twig/EasyAdminTwigExtension.php @@ -6,6 +6,7 @@ use EasyCorp\Bundle\EasyAdminBundle\Dto\FieldLayoutDto; use EasyCorp\Bundle\EasyAdminBundle\Factory\FormLayoutFactory; use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; +use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProviderInterface; use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator; use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGeneratorInterface; use Symfony\Component\DependencyInjection\ServiceLocator; @@ -30,7 +31,7 @@ class EasyAdminTwigExtension extends AbstractExtension implements GlobalsInterfa private AdminContextProvider $adminContextProvider; private ?CsrfTokenManagerInterface $csrfTokenManager; - public function __construct(ServiceLocator $serviceLocator, AdminContextProvider $adminContextProvider, ?CsrfTokenManagerInterface $csrfTokenManager) + public function __construct(ServiceLocator $serviceLocator, AdminContextProviderInterface $adminContextProvider, ?CsrfTokenManagerInterface $csrfTokenManager) { $this->serviceLocator = $serviceLocator; $this->adminContextProvider = $adminContextProvider; From 6ecf9084d7b0cbe8b981329b66ba4054f03353e6 Mon Sep 17 00:00:00 2001 From: Maximilian Graf Schimmelmann Date: Thu, 4 Jan 2024 14:59:14 +0100 Subject: [PATCH 2/6] removed property declaration and implemented PHP8 shorthand construct initialization of properties. Signed-off-by: Maximilian Graf Schimmelmann --- src/EventListener/CrudResponseListener.php | 12 ++++------- src/EventListener/ExceptionListener.php | 15 +++++-------- src/Factory/ActionFactory.php | 18 ++++++---------- src/Factory/FieldFactory.php | 18 ++++++---------- src/Factory/FilterFactory.php | 11 ++++------ src/Factory/MenuFactory.php | 21 +++++++------------ src/Factory/PaginatorFactory.php | 12 ++++------- .../Configurator/CommonPostConfigurator.php | 12 ++++------- .../Extension/EaCrudFormTypeExtension.php | 9 +++----- src/Inspector/DataCollector.php | 9 +++----- src/Orm/EntityRepository.php | 21 +++++++------------ src/Provider/FieldProvider.php | 9 +++----- src/Router/AdminUrlGenerator.php | 14 +++++-------- src/Security/SecurityVoter.php | 12 ++++------- src/Twig/EasyAdminTwigExtension.php | 15 +++++-------- 15 files changed, 70 insertions(+), 138 deletions(-) diff --git a/src/EventListener/CrudResponseListener.php b/src/EventListener/CrudResponseListener.php index 519837760e..6efcb064e6 100644 --- a/src/EventListener/CrudResponseListener.php +++ b/src/EventListener/CrudResponseListener.php @@ -15,14 +15,10 @@ */ final class CrudResponseListener { - private AdminContextProvider $adminContextProvider; - private Environment $twig; - - public function __construct(AdminContextProviderInterface $adminContextProvider, Environment $twig) - { - $this->adminContextProvider = $adminContextProvider; - $this->twig = $twig; - } + public function __construct( + private AdminContextProviderInterface $adminContextProvider, + private Environment $twig + ) {} public function onKernelView(ViewEvent $event): void { diff --git a/src/EventListener/ExceptionListener.php b/src/EventListener/ExceptionListener.php index af7b91c259..8a990f806d 100644 --- a/src/EventListener/ExceptionListener.php +++ b/src/EventListener/ExceptionListener.php @@ -22,16 +22,11 @@ */ final class ExceptionListener { - private bool $kernelDebug; - private AdminContextProvider $adminContextProvider; - private Environment $twig; - - public function __construct(bool $kernelDebug, AdminContextProviderInterface $adminContextProvider, Environment $twig) - { - $this->kernelDebug = $kernelDebug; - $this->adminContextProvider = $adminContextProvider; - $this->twig = $twig; - } + public function __construct( + private bool $kernelDebug, + private AdminContextProviderInterface $adminContextProvider, + private Environment $twig + ) {} public function onKernelException(ExceptionEvent $event) { diff --git a/src/Factory/ActionFactory.php b/src/Factory/ActionFactory.php index a8065f0026..7760ca1d8a 100644 --- a/src/Factory/ActionFactory.php +++ b/src/Factory/ActionFactory.php @@ -25,18 +25,12 @@ */ final class ActionFactory { - private AdminContextProvider $adminContextProvider; - private AuthorizationCheckerInterface $authChecker; - private AdminUrlGeneratorInterface $adminUrlGenerator; - private ?CsrfTokenManagerInterface $csrfTokenManager; - - public function __construct(AdminContextProviderInterface $adminContextProvider, AuthorizationCheckerInterface $authChecker, AdminUrlGeneratorInterface $adminUrlGenerator, ?CsrfTokenManagerInterface $csrfTokenManager = null) - { - $this->adminContextProvider = $adminContextProvider; - $this->authChecker = $authChecker; - $this->adminUrlGenerator = $adminUrlGenerator; - $this->csrfTokenManager = $csrfTokenManager; - } + public function __construct( + private AdminContextProviderInterface $adminContextProvider, + private AuthorizationCheckerInterface $authChecker, + private AdminUrlGeneratorInterface $adminUrlGenerator, + private ?CsrfTokenManagerInterface $csrfTokenManager = null + ) {} public function processEntityActions(EntityDto $entityDto, ActionConfigDto $actionsDto): void { diff --git a/src/Factory/FieldFactory.php b/src/Factory/FieldFactory.php index 2dc74e8ba1..d06470af49 100644 --- a/src/Factory/FieldFactory.php +++ b/src/Factory/FieldFactory.php @@ -56,18 +56,12 @@ final class FieldFactory Types::TIME_IMMUTABLE => TimeField::class, ]; - private AdminContextProvider $adminContextProvider; - private AuthorizationCheckerInterface $authorizationChecker; - private iterable $fieldConfigurators; - private FormLayoutFactory $fieldLayoutFactory; - - public function __construct(AdminContextProviderInterface $adminContextProvider, AuthorizationCheckerInterface $authorizationChecker, iterable $fieldConfigurators, FormLayoutFactory $fieldLayoutFactory) - { - $this->adminContextProvider = $adminContextProvider; - $this->authorizationChecker = $authorizationChecker; - $this->fieldConfigurators = $fieldConfigurators; - $this->fieldLayoutFactory = $fieldLayoutFactory; - } + public function __construct( + private AdminContextProviderInterface $adminContextProvider, + private AuthorizationCheckerInterface $authorizationChecker, + private iterable $fieldConfigurators, + private FormLayoutFactory $fieldLayoutFactory + ) {} public function processFields(EntityDto $entityDto, FieldCollection $fields): void { diff --git a/src/Factory/FilterFactory.php b/src/Factory/FilterFactory.php index 7e477a572f..77385dbd27 100644 --- a/src/Factory/FilterFactory.php +++ b/src/Factory/FilterFactory.php @@ -24,8 +24,6 @@ */ final class FilterFactory { - private AdminContextProvider $adminContextProvider; - private iterable $filterConfigurators; private static array $doctrineTypeToFilterClass = [ 'json_array' => ArrayFilter::class, Types::SIMPLE_ARRAY => ArrayFilter::class, @@ -53,11 +51,10 @@ final class FilterFactory Types::TEXT => TextFilter::class, ]; - public function __construct(AdminContextProviderInterface $adminContextProvider, iterable $filterConfigurators) - { - $this->adminContextProvider = $adminContextProvider; - $this->filterConfigurators = $filterConfigurators; - } + public function __construct( + private AdminContextProviderInterface $adminContextProvider, + private iterable $filterConfigurators + ) {} public function create(FilterConfigDto $filterConfig, FieldCollection $fields, EntityDto $entityDto): FilterCollection { diff --git a/src/Factory/MenuFactory.php b/src/Factory/MenuFactory.php index a33c80fcc4..303a6e0107 100644 --- a/src/Factory/MenuFactory.php +++ b/src/Factory/MenuFactory.php @@ -25,20 +25,13 @@ */ final class MenuFactory implements MenuFactoryInterface { - private AdminContextProvider $adminContextProvider; - private AuthorizationCheckerInterface $authChecker; - private LogoutUrlGenerator $logoutUrlGenerator; - private AdminUrlGeneratorInterface $adminUrlGenerator; - private MenuItemMatcherInterface $menuItemMatcher; - - public function __construct(AdminContextProviderInterface $adminContextProvider, AuthorizationCheckerInterface $authChecker, LogoutUrlGenerator $logoutUrlGenerator, AdminUrlGeneratorInterface $adminUrlGenerator, MenuItemMatcherInterface $menuItemMatcher) - { - $this->adminContextProvider = $adminContextProvider; - $this->authChecker = $authChecker; - $this->logoutUrlGenerator = $logoutUrlGenerator; - $this->adminUrlGenerator = $adminUrlGenerator; - $this->menuItemMatcher = $menuItemMatcher; - } + public function __construct( + private AdminContextProviderInterface $adminContextProvider, + private AuthorizationCheckerInterface $authChecker, + private LogoutUrlGenerator $logoutUrlGenerator, + private AdminUrlGeneratorInterface $adminUrlGenerator, + private MenuItemMatcherInterface $menuItemMatcher + ) {} /** * @param MenuItemInterface[] $menuItems diff --git a/src/Factory/PaginatorFactory.php b/src/Factory/PaginatorFactory.php index 80cbd3322b..32a3ab2203 100644 --- a/src/Factory/PaginatorFactory.php +++ b/src/Factory/PaginatorFactory.php @@ -12,14 +12,10 @@ */ final class PaginatorFactory { - private AdminContextProvider $adminContextProvider; - private EntityPaginatorInterface $entityPaginator; - - public function __construct(AdminContextProviderInterface $adminContextProvider, EntityPaginatorInterface $entityPaginator) - { - $this->adminContextProvider = $adminContextProvider; - $this->entityPaginator = $entityPaginator; - } + public function __construct( + private AdminContextProviderInterface $adminContextProvider, + private EntityPaginatorInterface $entityPaginator + ) {} public function create(QueryBuilder $queryBuilder): EntityPaginatorInterface { diff --git a/src/Field/Configurator/CommonPostConfigurator.php b/src/Field/Configurator/CommonPostConfigurator.php index 7a876fdc6b..7921957002 100644 --- a/src/Field/Configurator/CommonPostConfigurator.php +++ b/src/Field/Configurator/CommonPostConfigurator.php @@ -17,14 +17,10 @@ */ final class CommonPostConfigurator implements FieldConfiguratorInterface { - private AdminContextProvider $adminContextProvider; - private string $charset; - - public function __construct(AdminContextProviderInterface $adminContextProvider, string $charset) - { - $this->adminContextProvider = $adminContextProvider; - $this->charset = $charset; - } + public function __construct( + private AdminContextProviderInterface $adminContextProvider, + private string $charset + ) {} public function supports(FieldDto $field, EntityDto $entityDto): bool { diff --git a/src/Form/Extension/EaCrudFormTypeExtension.php b/src/Form/Extension/EaCrudFormTypeExtension.php index 3e7885c0d4..4e61abd178 100644 --- a/src/Form/Extension/EaCrudFormTypeExtension.php +++ b/src/Form/Extension/EaCrudFormTypeExtension.php @@ -19,12 +19,9 @@ */ class EaCrudFormTypeExtension extends AbstractTypeExtension { - private AdminContextProvider $adminContextProvider; - - public function __construct(AdminContextProviderInterface $adminContextProvider) - { - $this->adminContextProvider = $adminContextProvider; - } + public function __construct( + private AdminContextProviderInterface $adminContextProvider + ) {} public function configureOptions(OptionsResolver $resolver): void { diff --git a/src/Inspector/DataCollector.php b/src/Inspector/DataCollector.php index 8d931265c9..59a5bb1900 100644 --- a/src/Inspector/DataCollector.php +++ b/src/Inspector/DataCollector.php @@ -18,12 +18,9 @@ */ class DataCollector extends BaseDataCollector { - private AdminContextProvider $adminContextProvider; - - public function __construct(AdminContextProviderInterface $adminContextProvider) - { - $this->adminContextProvider = $adminContextProvider; - } + public function __construct( + private AdminContextProviderInterface $adminContextProvider + ) {} public function reset(): void { diff --git a/src/Orm/EntityRepository.php b/src/Orm/EntityRepository.php index a6f6ab598e..03dc0c53c4 100644 --- a/src/Orm/EntityRepository.php +++ b/src/Orm/EntityRepository.php @@ -30,20 +30,13 @@ */ final class EntityRepository implements EntityRepositoryInterface { - private AdminContextProvider $adminContextProvider; - private ManagerRegistry $doctrine; - private EntityFactory $entityFactory; - private FormFactory $formFactory; - private EventDispatcherInterface $eventDispatcher; - - public function __construct(AdminContextProviderInterface $adminContextProvider, ManagerRegistry $doctrine, EntityFactory $entityFactory, FormFactory $formFactory, EventDispatcherInterface $eventDispatcher) - { - $this->adminContextProvider = $adminContextProvider; - $this->doctrine = $doctrine; - $this->entityFactory = $entityFactory; - $this->formFactory = $formFactory; - $this->eventDispatcher = $eventDispatcher; - } + public function __construct( + private AdminContextProviderInterface $adminContextProvider, + private ManagerRegistry $doctrine, + private EntityFactory $entityFactory, + private FormFactory $formFactory, + private EventDispatcherInterface $eventDispatcher + ) {} public function createQueryBuilder(SearchDto $searchDto, EntityDto $entityDto, FieldCollection $fields, FilterCollection $filters): QueryBuilder { diff --git a/src/Provider/FieldProvider.php b/src/Provider/FieldProvider.php index 5e4300cde6..4af38dca78 100644 --- a/src/Provider/FieldProvider.php +++ b/src/Provider/FieldProvider.php @@ -11,12 +11,9 @@ */ final class FieldProvider { - private AdminContextProvider $adminContextProvider; - - public function __construct(AdminContextProviderInterface $adminContextProvider) - { - $this->adminContextProvider = $adminContextProvider; - } + public function __construct( + private AdminContextProviderInterface $adminContextProvider + ) {} public function getDefaultFields(string $pageName): array { diff --git a/src/Router/AdminUrlGenerator.php b/src/Router/AdminUrlGenerator.php index 79978fb6db..cab69dbd2f 100644 --- a/src/Router/AdminUrlGenerator.php +++ b/src/Router/AdminUrlGenerator.php @@ -17,21 +17,17 @@ final class AdminUrlGenerator implements AdminUrlGeneratorInterface { private bool $isInitialized = false; - private AdminContextProvider $adminContextProvider; - private UrlGeneratorInterface $urlGenerator; - private DashboardControllerRegistry $dashboardControllerRegistry; private ?string $dashboardRoute = null; private ?bool $includeReferrer = null; private array $routeParameters = []; private ?string $currentPageReferrer = null; private ?string $customPageReferrer = null; - public function __construct(AdminContextProviderInterface $adminContextProvider, UrlGeneratorInterface $urlGenerator, DashboardControllerRegistry $dashboardControllerRegistry) - { - $this->adminContextProvider = $adminContextProvider; - $this->urlGenerator = $urlGenerator; - $this->dashboardControllerRegistry = $dashboardControllerRegistry; - } + public function __construct( + private AdminContextProviderInterface $adminContextProvider, + private UrlGeneratorInterface $urlGenerator, + private DashboardControllerRegistry $dashboardControllerRegistry + ) {} /** * @return AdminUrlGenerator diff --git a/src/Security/SecurityVoter.php b/src/Security/SecurityVoter.php index 3c10e33db8..2448d2ba15 100644 --- a/src/Security/SecurityVoter.php +++ b/src/Security/SecurityVoter.php @@ -18,14 +18,10 @@ */ final class SecurityVoter extends Voter { - private AuthorizationCheckerInterface $authorizationChecker; - private AdminContextProvider $adminContextProvider; - - public function __construct(AuthorizationCheckerInterface $authorizationChecker, AdminContextProviderInterface $adminContextProvider) - { - $this->authorizationChecker = $authorizationChecker; - $this->adminContextProvider = $adminContextProvider; - } + public function __construct( + private AuthorizationCheckerInterface $authorizationChecker, + private AdminContextProviderInterface $adminContextProvider, + ) {} protected function supports(string $permissionName, mixed $subject): bool { diff --git a/src/Twig/EasyAdminTwigExtension.php b/src/Twig/EasyAdminTwigExtension.php index 16434a50c1..34b6e5568f 100644 --- a/src/Twig/EasyAdminTwigExtension.php +++ b/src/Twig/EasyAdminTwigExtension.php @@ -27,16 +27,11 @@ */ class EasyAdminTwigExtension extends AbstractExtension implements GlobalsInterface { - private ServiceLocator $serviceLocator; - private AdminContextProvider $adminContextProvider; - private ?CsrfTokenManagerInterface $csrfTokenManager; - - public function __construct(ServiceLocator $serviceLocator, AdminContextProviderInterface $adminContextProvider, ?CsrfTokenManagerInterface $csrfTokenManager) - { - $this->serviceLocator = $serviceLocator; - $this->adminContextProvider = $adminContextProvider; - $this->csrfTokenManager = $csrfTokenManager; - } + public function __construct( + private ServiceLocator $serviceLocator, + private AdminContextProviderInterface $adminContextProvider, + private ?CsrfTokenManagerInterface $csrfTokenManager + ) {} public function getFunctions(): array { From 5884579f8892521802749e85694dce599d0525a1 Mon Sep 17 00:00:00 2001 From: Maximilian Graf Schimmelmann Date: Thu, 4 Jan 2024 15:04:52 +0100 Subject: [PATCH 3/6] Added whitespaces, fixed Phpcs feedback, removed unused use imports. --- src/EventListener/CrudResponseListener.php | 4 ++-- src/EventListener/ExceptionListener.php | 4 ++-- src/Factory/ActionFactory.php | 4 ++-- src/Factory/FieldFactory.php | 4 ++-- src/Factory/FilterFactory.php | 4 ++-- src/Factory/MenuFactory.php | 4 ++-- src/Factory/PaginatorFactory.php | 4 ++-- src/Field/Configurator/CommonPostConfigurator.php | 4 ++-- src/Form/Extension/EaCrudFormTypeExtension.php | 4 ++-- src/Inspector/DataCollector.php | 4 ++-- src/Menu/MenuItemMatcher.php | 1 - src/Orm/EntityRepository.php | 4 ++-- src/Provider/AdminContextProvider.php | 3 ++- src/Provider/AdminContextProviderInterface.php | 1 - src/Provider/FieldProvider.php | 3 ++- src/Router/AdminUrlGenerator.php | 4 ++-- src/Security/SecurityVoter.php | 4 ++-- src/Twig/EasyAdminTwigExtension.php | 4 ++-- 18 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/EventListener/CrudResponseListener.php b/src/EventListener/CrudResponseListener.php index 6efcb064e6..4424b88103 100644 --- a/src/EventListener/CrudResponseListener.php +++ b/src/EventListener/CrudResponseListener.php @@ -3,7 +3,6 @@ namespace EasyCorp\Bundle\EasyAdminBundle\EventListener; use EasyCorp\Bundle\EasyAdminBundle\Config\KeyValueStore; -use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProviderInterface; use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\Response; @@ -18,7 +17,8 @@ final class CrudResponseListener public function __construct( private AdminContextProviderInterface $adminContextProvider, private Environment $twig - ) {} + ) { + } public function onKernelView(ViewEvent $event): void { diff --git a/src/EventListener/ExceptionListener.php b/src/EventListener/ExceptionListener.php index 8a990f806d..6999fdbc4c 100644 --- a/src/EventListener/ExceptionListener.php +++ b/src/EventListener/ExceptionListener.php @@ -4,7 +4,6 @@ use EasyCorp\Bundle\EasyAdminBundle\Exception\BaseException; use EasyCorp\Bundle\EasyAdminBundle\Exception\FlattenException; -use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProviderInterface; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Event\ExceptionEvent; @@ -26,7 +25,8 @@ public function __construct( private bool $kernelDebug, private AdminContextProviderInterface $adminContextProvider, private Environment $twig - ) {} + ) { + } public function onKernelException(ExceptionEvent $event) { diff --git a/src/Factory/ActionFactory.php b/src/Factory/ActionFactory.php index 7760ca1d8a..10b6b707f4 100644 --- a/src/Factory/ActionFactory.php +++ b/src/Factory/ActionFactory.php @@ -9,7 +9,6 @@ use EasyCorp\Bundle\EasyAdminBundle\Dto\ActionConfigDto; use EasyCorp\Bundle\EasyAdminBundle\Dto\ActionDto; use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto; -use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProviderInterface; use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGeneratorInterface; use EasyCorp\Bundle\EasyAdminBundle\Security\Permission; @@ -30,7 +29,8 @@ public function __construct( private AuthorizationCheckerInterface $authChecker, private AdminUrlGeneratorInterface $adminUrlGenerator, private ?CsrfTokenManagerInterface $csrfTokenManager = null - ) {} + ) { + } public function processEntityActions(EntityDto $entityDto, ActionConfigDto $actionsDto): void { diff --git a/src/Factory/FieldFactory.php b/src/Factory/FieldFactory.php index d06470af49..9a5209353c 100644 --- a/src/Factory/FieldFactory.php +++ b/src/Factory/FieldFactory.php @@ -19,7 +19,6 @@ use EasyCorp\Bundle\EasyAdminBundle\Field\TextField; use EasyCorp\Bundle\EasyAdminBundle\Field\TimeField; use EasyCorp\Bundle\EasyAdminBundle\Form\Type\EaFormRowType; -use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProviderInterface; use EasyCorp\Bundle\EasyAdminBundle\Security\Permission; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; @@ -61,7 +60,8 @@ public function __construct( private AuthorizationCheckerInterface $authorizationChecker, private iterable $fieldConfigurators, private FormLayoutFactory $fieldLayoutFactory - ) {} + ) { + } public function processFields(EntityDto $entityDto, FieldCollection $fields): void { diff --git a/src/Factory/FilterFactory.php b/src/Factory/FilterFactory.php index 77385dbd27..b41052e590 100644 --- a/src/Factory/FilterFactory.php +++ b/src/Factory/FilterFactory.php @@ -15,7 +15,6 @@ use EasyCorp\Bundle\EasyAdminBundle\Filter\EntityFilter; use EasyCorp\Bundle\EasyAdminBundle\Filter\NumericFilter; use EasyCorp\Bundle\EasyAdminBundle\Filter\TextFilter; -use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProviderInterface; /** @@ -54,7 +53,8 @@ final class FilterFactory public function __construct( private AdminContextProviderInterface $adminContextProvider, private iterable $filterConfigurators - ) {} + ) { + } public function create(FilterConfigDto $filterConfig, FieldCollection $fields, EntityDto $entityDto): FilterCollection { diff --git a/src/Factory/MenuFactory.php b/src/Factory/MenuFactory.php index 303a6e0107..2389e1f53b 100644 --- a/src/Factory/MenuFactory.php +++ b/src/Factory/MenuFactory.php @@ -11,7 +11,6 @@ use EasyCorp\Bundle\EasyAdminBundle\Dto\MainMenuDto; use EasyCorp\Bundle\EasyAdminBundle\Dto\MenuItemDto; use EasyCorp\Bundle\EasyAdminBundle\Dto\UserMenuDto; -use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProviderInterface; use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGeneratorInterface; use EasyCorp\Bundle\EasyAdminBundle\Security\Permission; @@ -31,7 +30,8 @@ public function __construct( private LogoutUrlGenerator $logoutUrlGenerator, private AdminUrlGeneratorInterface $adminUrlGenerator, private MenuItemMatcherInterface $menuItemMatcher - ) {} + ) { + } /** * @param MenuItemInterface[] $menuItems diff --git a/src/Factory/PaginatorFactory.php b/src/Factory/PaginatorFactory.php index 32a3ab2203..66df23a9ff 100644 --- a/src/Factory/PaginatorFactory.php +++ b/src/Factory/PaginatorFactory.php @@ -4,7 +4,6 @@ use Doctrine\ORM\QueryBuilder; use EasyCorp\Bundle\EasyAdminBundle\Contracts\Orm\EntityPaginatorInterface; -use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProviderInterface; /** @@ -15,7 +14,8 @@ final class PaginatorFactory public function __construct( private AdminContextProviderInterface $adminContextProvider, private EntityPaginatorInterface $entityPaginator - ) {} + ) { + } public function create(QueryBuilder $queryBuilder): EntityPaginatorInterface { diff --git a/src/Field/Configurator/CommonPostConfigurator.php b/src/Field/Configurator/CommonPostConfigurator.php index 7921957002..8023701b74 100644 --- a/src/Field/Configurator/CommonPostConfigurator.php +++ b/src/Field/Configurator/CommonPostConfigurator.php @@ -7,7 +7,6 @@ use EasyCorp\Bundle\EasyAdminBundle\Contracts\Field\FieldConfiguratorInterface; use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto; use EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto; -use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProviderInterface; use function Symfony\Component\String\u; use Twig\Markup; @@ -20,7 +19,8 @@ final class CommonPostConfigurator implements FieldConfiguratorInterface public function __construct( private AdminContextProviderInterface $adminContextProvider, private string $charset - ) {} + ) { + } public function supports(FieldDto $field, EntityDto $entityDto): bool { diff --git a/src/Form/Extension/EaCrudFormTypeExtension.php b/src/Form/Extension/EaCrudFormTypeExtension.php index 4e61abd178..d9d341250c 100644 --- a/src/Form/Extension/EaCrudFormTypeExtension.php +++ b/src/Form/Extension/EaCrudFormTypeExtension.php @@ -3,7 +3,6 @@ namespace EasyCorp\Bundle\EasyAdminBundle\Form\Extension; use EasyCorp\Bundle\EasyAdminBundle\Dto\FormVarsDto; -use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProviderInterface; use Symfony\Component\Form\AbstractTypeExtension; use Symfony\Component\Form\Extension\Core\Type\FormType; @@ -21,7 +20,8 @@ class EaCrudFormTypeExtension extends AbstractTypeExtension { public function __construct( private AdminContextProviderInterface $adminContextProvider - ) {} + ) { + } public function configureOptions(OptionsResolver $resolver): void { diff --git a/src/Inspector/DataCollector.php b/src/Inspector/DataCollector.php index 59a5bb1900..c9e44d1b96 100644 --- a/src/Inspector/DataCollector.php +++ b/src/Inspector/DataCollector.php @@ -4,7 +4,6 @@ use EasyCorp\Bundle\EasyAdminBundle\Config\Option\EA; use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext; -use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProviderInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -20,7 +19,8 @@ class DataCollector extends BaseDataCollector { public function __construct( private AdminContextProviderInterface $adminContextProvider - ) {} + ) { + } public function reset(): void { diff --git a/src/Menu/MenuItemMatcher.php b/src/Menu/MenuItemMatcher.php index b13d7cf50a..a9714e6749 100644 --- a/src/Menu/MenuItemMatcher.php +++ b/src/Menu/MenuItemMatcher.php @@ -6,7 +6,6 @@ use EasyCorp\Bundle\EasyAdminBundle\Config\Option\EA; use EasyCorp\Bundle\EasyAdminBundle\Contracts\Menu\MenuItemMatcherInterface; use EasyCorp\Bundle\EasyAdminBundle\Dto\MenuItemDto; -use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProviderInterface; /** diff --git a/src/Orm/EntityRepository.php b/src/Orm/EntityRepository.php index 03dc0c53c4..36ec3c07ce 100644 --- a/src/Orm/EntityRepository.php +++ b/src/Orm/EntityRepository.php @@ -19,7 +19,6 @@ use EasyCorp\Bundle\EasyAdminBundle\Factory\EntityFactory; use EasyCorp\Bundle\EasyAdminBundle\Factory\FormFactory; use EasyCorp\Bundle\EasyAdminBundle\Form\Type\ComparisonType; -use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProviderInterface; use Symfony\Component\Uid\Ulid; use Symfony\Component\Uid\Uuid; @@ -36,7 +35,8 @@ public function __construct( private EntityFactory $entityFactory, private FormFactory $formFactory, private EventDispatcherInterface $eventDispatcher - ) {} + ) { + } public function createQueryBuilder(SearchDto $searchDto, EntityDto $entityDto, FieldCollection $fields, FilterCollection $filters): QueryBuilder { diff --git a/src/Provider/AdminContextProvider.php b/src/Provider/AdminContextProvider.php index 6ddab55649..968d672c77 100644 --- a/src/Provider/AdminContextProvider.php +++ b/src/Provider/AdminContextProvider.php @@ -13,7 +13,8 @@ final class AdminContextProvider implements AdminContextProviderInterface { public function __construct( private RequestStack $requestStack - ) {} + ) { + } public function getContext(): ?AdminContext { diff --git a/src/Provider/AdminContextProviderInterface.php b/src/Provider/AdminContextProviderInterface.php index e40e82bfb9..d579b993b4 100644 --- a/src/Provider/AdminContextProviderInterface.php +++ b/src/Provider/AdminContextProviderInterface.php @@ -4,7 +4,6 @@ namespace EasyCorp\Bundle\EasyAdminBundle\Provider; - use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext; /** diff --git a/src/Provider/FieldProvider.php b/src/Provider/FieldProvider.php index 4af38dca78..e3a15b7003 100644 --- a/src/Provider/FieldProvider.php +++ b/src/Provider/FieldProvider.php @@ -13,7 +13,8 @@ final class FieldProvider { public function __construct( private AdminContextProviderInterface $adminContextProvider - ) {} + ) { + } public function getDefaultFields(string $pageName): array { diff --git a/src/Router/AdminUrlGenerator.php b/src/Router/AdminUrlGenerator.php index cab69dbd2f..b4862cc033 100644 --- a/src/Router/AdminUrlGenerator.php +++ b/src/Router/AdminUrlGenerator.php @@ -6,7 +6,6 @@ use EasyCorp\Bundle\EasyAdminBundle\Config\Option\EA; use EasyCorp\Bundle\EasyAdminBundle\Contracts\Controller\DashboardControllerInterface; use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController; -use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProviderInterface; use EasyCorp\Bundle\EasyAdminBundle\Registry\DashboardControllerRegistry; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; @@ -27,7 +26,8 @@ public function __construct( private AdminContextProviderInterface $adminContextProvider, private UrlGeneratorInterface $urlGenerator, private DashboardControllerRegistry $dashboardControllerRegistry - ) {} + ) { + } /** * @return AdminUrlGenerator diff --git a/src/Security/SecurityVoter.php b/src/Security/SecurityVoter.php index 2448d2ba15..c044ef61a0 100644 --- a/src/Security/SecurityVoter.php +++ b/src/Security/SecurityVoter.php @@ -7,7 +7,6 @@ use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto; use EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto; use EasyCorp\Bundle\EasyAdminBundle\Dto\MenuItemDto; -use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProviderInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; @@ -21,7 +20,8 @@ final class SecurityVoter extends Voter public function __construct( private AuthorizationCheckerInterface $authorizationChecker, private AdminContextProviderInterface $adminContextProvider, - ) {} + ) { + } protected function supports(string $permissionName, mixed $subject): bool { diff --git a/src/Twig/EasyAdminTwigExtension.php b/src/Twig/EasyAdminTwigExtension.php index 34b6e5568f..da41343388 100644 --- a/src/Twig/EasyAdminTwigExtension.php +++ b/src/Twig/EasyAdminTwigExtension.php @@ -5,7 +5,6 @@ use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection; use EasyCorp\Bundle\EasyAdminBundle\Dto\FieldLayoutDto; use EasyCorp\Bundle\EasyAdminBundle\Factory\FormLayoutFactory; -use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProviderInterface; use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator; use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGeneratorInterface; @@ -31,7 +30,8 @@ public function __construct( private ServiceLocator $serviceLocator, private AdminContextProviderInterface $adminContextProvider, private ?CsrfTokenManagerInterface $csrfTokenManager - ) {} + ) { + } public function getFunctions(): array { From 0bfcda2cc2b27f49f6647128a99ca11355952b0d Mon Sep 17 00:00:00 2001 From: Maximilian Graf Schimmelmann Date: Thu, 4 Jan 2024 15:05:39 +0100 Subject: [PATCH 4/6] Removed phpdoc from interface --- src/Provider/AdminContextProviderInterface.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Provider/AdminContextProviderInterface.php b/src/Provider/AdminContextProviderInterface.php index d579b993b4..c6c359719d 100644 --- a/src/Provider/AdminContextProviderInterface.php +++ b/src/Provider/AdminContextProviderInterface.php @@ -6,9 +6,6 @@ use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext; -/** - * @author Javier Eguiluz - */ interface AdminContextProviderInterface { public function getContext(): ?AdminContext; From dd090bf34e0405b40d3abfca0df4c0a735190cc7 Mon Sep 17 00:00:00 2001 From: Maximilian Graf Schimmelmann Date: Thu, 4 Jan 2024 15:10:49 +0100 Subject: [PATCH 5/6] Add shorthand initialization for properties in constructor for argument resolver classes --- src/ArgumentResolver/AdminContextResolver.php | 17 +++++--------- .../BatchActionDtoResolver.php | 23 +++++++------------ 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/src/ArgumentResolver/AdminContextResolver.php b/src/ArgumentResolver/AdminContextResolver.php index 65c34e1114..34c7df41b8 100644 --- a/src/ArgumentResolver/AdminContextResolver.php +++ b/src/ArgumentResolver/AdminContextResolver.php @@ -3,7 +3,6 @@ namespace EasyCorp\Bundle\EasyAdminBundle\ArgumentResolver; use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext; -use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProviderInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface; @@ -16,11 +15,9 @@ if (interface_exists(ValueResolverInterface::class)) { final class AdminContextResolver implements ValueResolverInterface { - private AdminContextProvider $adminContextProvider; - - public function __construct(AdminContextProviderInterface $adminContextProvider) - { - $this->adminContextProvider = $adminContextProvider; + public function __construct( + private AdminContextProviderInterface $adminContextProvider + ) { } public function resolve(Request $request, ArgumentMetadata $argument): iterable @@ -35,11 +32,9 @@ public function resolve(Request $request, ArgumentMetadata $argument): iterable } else { final class AdminContextResolver implements ArgumentValueResolverInterface { - private AdminContextProvider $adminContextProvider; - - public function __construct(AdminContextProviderInterface $adminContextProvider) - { - $this->adminContextProvider = $adminContextProvider; + public function __construct( + private AdminContextProviderInterface $adminContextProvider + ) { } public function supports(Request $request, ArgumentMetadata $argument): bool diff --git a/src/ArgumentResolver/BatchActionDtoResolver.php b/src/ArgumentResolver/BatchActionDtoResolver.php index 2eae340ccb..ede6fb148b 100644 --- a/src/ArgumentResolver/BatchActionDtoResolver.php +++ b/src/ArgumentResolver/BatchActionDtoResolver.php @@ -4,7 +4,6 @@ use EasyCorp\Bundle\EasyAdminBundle\Config\Option\EA; use EasyCorp\Bundle\EasyAdminBundle\Dto\BatchActionDto; -use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProviderInterface; use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGeneratorInterface; use Symfony\Component\HttpFoundation\Request; @@ -18,13 +17,10 @@ if (interface_exists(ValueResolverInterface::class)) { final class BatchActionDtoResolver implements ValueResolverInterface { - private AdminContextProvider $adminContextProvider; - private AdminUrlGeneratorInterface $adminUrlGenerator; - - public function __construct(AdminContextProviderInterface $adminContextProvider, AdminUrlGeneratorInterface $adminUrlGenerator) - { - $this->adminContextProvider = $adminContextProvider; - $this->adminUrlGenerator = $adminUrlGenerator; + public function __construct( + private AdminContextProviderInterface $adminContextProvider, + private AdminUrlGeneratorInterface $adminUrlGenerator + ) { } public function resolve(Request $request, ArgumentMetadata $argument): iterable @@ -54,13 +50,10 @@ public function resolve(Request $request, ArgumentMetadata $argument): iterable } else { final class BatchActionDtoResolver implements ArgumentValueResolverInterface { - private AdminContextProvider $adminContextProvider; - private AdminUrlGeneratorInterface $adminUrlGenerator; - - public function __construct(AdminContextProviderInterface $adminContextProvider, AdminUrlGeneratorInterface $adminUrlGenerator) - { - $this->adminContextProvider = $adminContextProvider; - $this->adminUrlGenerator = $adminUrlGenerator; + public function __construct( + private AdminContextProviderInterface $adminContextProvider, + private AdminUrlGeneratorInterface $adminUrlGenerator + ) { } public function supports(Request $request, ArgumentMetadata $argument): bool From c0a5832bea2e276a896b3e30d0391d22861582bf Mon Sep 17 00:00:00 2001 From: Maximilian Graf Schimmelmann Date: Thu, 7 Nov 2024 01:49:10 +0100 Subject: [PATCH 6/6] Fix bug with tabs being invisible when an association or similar has property with same label. --- src/Factory/FormLayoutFactory.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Factory/FormLayoutFactory.php b/src/Factory/FormLayoutFactory.php index 5d3893827c..17d55f49ae 100644 --- a/src/Factory/FormLayoutFactory.php +++ b/src/Factory/FormLayoutFactory.php @@ -180,7 +180,11 @@ private function linearizeLayoutConfiguration(FieldCollection $fields): void if ($fieldDto->isFormTab()) { $isTabActive = 0 === \count($tabs); - $tabId = sprintf('tab-%s', $fieldDto->getLabel() ? $slugger->slug(strip_tags($fieldDto->getLabel()))->lower()->toString() : ++$tabsWithoutLabelCounter); + $tabId = sprintf('tab-%s-%s', $fieldDto->getLabel() + ? $slugger->slug(strip_tags($fieldDto->getLabel()))->lower()->toString() + : ++$tabsWithoutLabelCounter, + uniqid(), + ); $fieldDto->setCustomOption(FormField::OPTION_TAB_ID, $tabId); $fieldDto->setCustomOption(FormField::OPTION_TAB_IS_ACTIVE, $isTabActive);