Inject services, no longer available in container by default

This commit is contained in:
2025-06-03 15:08:26 +02:00
parent e51a3c7525
commit b9a9983b88
4 changed files with 54 additions and 15 deletions

View File

@@ -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);
}