diff --git a/src/Bundle/ChillMainBundle/CRUD/Controller/CRUDController.php b/src/Bundle/ChillMainBundle/CRUD/Controller/CRUDController.php index a2f11d90e..c1dc0b2ce 100644 --- a/src/Bundle/ChillMainBundle/CRUD/Controller/CRUDController.php +++ b/src/Bundle/ChillMainBundle/CRUD/Controller/CRUDController.php @@ -27,6 +27,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\Serializer\SerializerInterface; +use Symfony\Contracts\Service\Attribute\Required; use Symfony\Contracts\Translation\TranslatorInterface; /** @@ -62,7 +63,46 @@ class CRUDController extends AbstractController */ protected array $crudConfig; - public function __construct(private readonly ManagerRegistry $managerRegistry) {} + protected Resolver $resolver; + protected AuthorizationHelper $authorizationHelper; + + protected EventDispatcherInterface $eventDispatcher; + + protected FilterOrderHelperFactoryInterface $filterOrderHelperFactory; + + protected ManagerRegistry $managerRegistry; + + #[Required] + public function setAuthorizationHelper(AuthorizationHelper $authorizationHelper): void + { + $this->authorizationHelper = $authorizationHelper; + } + + #[Required] + public function setResolver(Resolver $resolver): void + { + $this->resolver = $resolver; + } + + #[Required] + public function setEventDispatcher(EventDispatcherInterface $eventDispatcher): void + { + $this->eventDispatcher = $eventDispatcher; + } + + #[Required] + public function setFilterOrderHelperFactory(FilterOrderHelperFactoryInterface $filterOrderHelperFactory): void + { + $this->filterOrderHelperFactory = $filterOrderHelperFactory; + } + + #[Required] + public function setManagerRegistry(ManagerRegistry $managerRegistry): void + { + $this->managerRegistry = $managerRegistry; + } + +// public function __construct(private readonly ManagerRegistry $managerRegistry) {} public function CRUD(?string $parameter): Response { @@ -155,7 +195,7 @@ class CRUDController extends AbstractController */ protected function buildDefaultRole($action) { - return $this->getCrudResolver()->buildDefaultRole( + return $this->resolver->buildDefaultRole( $this->getCrudName(), $action ); @@ -595,10 +635,10 @@ class CRUDController extends AbstractController return $this->crudConfig['actions'][$action]; } - protected function getAuthorizationHelper(): AuthorizationHelper +/* protected function getAuthorizationHelper(): AuthorizationHelper { return $this->container->get(AuthorizationHelper::class); - } + }*/ /** * @return string the crud name @@ -608,10 +648,10 @@ class CRUDController extends AbstractController return $this->crudConfig['name']; } - protected function getCrudResolver(): Resolver +/* protected function getCrudResolver(): Resolver { return $this->get(Resolver::class); - } + }*/ protected function getDefaultDeleteFormClass($action) { @@ -638,15 +678,15 @@ class CRUDController extends AbstractController return $this->crudConfig['class']; } - protected function getEventDispatcher(): EventDispatcherInterface +/* protected function getEventDispatcher(): EventDispatcherInterface { return $this->get(EventDispatcherInterface::class); - } + }*/ - protected function getFilterOrderHelperFactory(): FilterOrderHelperFactoryInterface +/* protected function getFilterOrderHelperFactory(): FilterOrderHelperFactoryInterface { return $this->get(FilterOrderHelperFactoryInterface::class); - } + }*/ /** * get the default form class from config. @@ -694,7 +734,7 @@ class CRUDController extends AbstractController */ protected function getReachableCenters(string $role, ?Scope $scope = null): array { - return $this->getAuthorizationHelper() + return $this->authorizationHelper ->getReachableCenters($this->getUser(), $role, $scope); } diff --git a/src/Bundle/ChillMainBundle/Controller/UserController.php b/src/Bundle/ChillMainBundle/Controller/UserController.php index 73930b4e6..d7e2642ad 100644 --- a/src/Bundle/ChillMainBundle/Controller/UserController.php +++ b/src/Bundle/ChillMainBundle/Controller/UserController.php @@ -50,7 +50,6 @@ class UserController extends CRUDController protected ParameterBagInterface $parameterBag, private readonly TranslatorInterface $translator, private readonly ChillSecurity $security, - private readonly ManagerRegistry $managerRegistry, ) {} #[\Symfony\Component\Routing\Attribute\Route(path: '/{_locale}/admin/main/user/{uid}/add_link_groupcenter', name: 'admin_user_add_groupcenter')] @@ -269,7 +268,7 @@ class UserController extends CRUDController protected function buildFilterOrderHelper(string $action, Request $request): ?FilterOrderHelper { - return $this->getFilterOrderHelperFactory() + return $this->filterOrderHelperFactory ->create(self::class) ->addSearchBox(['label']) ->addCheckbox('activeFilter', [true => 'Active', false => 'Inactive'], ['Active']) diff --git a/src/Bundle/ChillPersonBundle/Controller/ClosingMotiveController.php b/src/Bundle/ChillPersonBundle/Controller/ClosingMotiveController.php index 0cea8d1f2..87cd9fda8 100644 --- a/src/Bundle/ChillPersonBundle/Controller/ClosingMotiveController.php +++ b/src/Bundle/ChillPersonBundle/Controller/ClosingMotiveController.php @@ -21,7 +21,7 @@ use Symfony\Component\HttpFoundation\Request; */ class ClosingMotiveController extends CRUDController { - public function __construct(private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) {} +// public function __construct(private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) {} /** * @param string $action diff --git a/src/Bundle/ChillThirdPartyBundle/Controller/ThirdPartyController.php b/src/Bundle/ChillThirdPartyBundle/Controller/ThirdPartyController.php index 31e190bf0..85fd05171 100644 --- a/src/Bundle/ChillThirdPartyBundle/Controller/ThirdPartyController.php +++ b/src/Bundle/ChillThirdPartyBundle/Controller/ThirdPartyController.php @@ -51,7 +51,7 @@ final class ThirdPartyController extends CRUDController protected function buildFilterOrderHelper(string $action, Request $request): ?FilterOrderHelper { - return $this->getFilterOrderHelperFactory() + return $this->filterOrderHelperFactory ->create(self::class) ->addSearchBox(['name', 'company_name', 'acronym']) // ->addToggle('only-active', [])