|
5 | 5 | use EasyCorp\Bundle\EasyAdminBundle\Config\Option\EA;
|
6 | 6 | use EasyCorp\Bundle\EasyAdminBundle\Contracts\Provider\AdminContextProviderInterface;
|
7 | 7 | use EasyCorp\Bundle\EasyAdminBundle\Dto\BatchActionDto;
|
8 |
| -use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; |
9 |
| -use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGeneratorInterface; |
10 | 8 | use Symfony\Component\HttpFoundation\Request;
|
11 |
| -use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface; |
12 | 9 | use Symfony\Component\HttpKernel\Controller\ValueResolverInterface;
|
13 | 10 | use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
|
14 | 11 |
|
15 | 12 | /*
|
16 | 13 | * @author Javier Eguiluz <[email protected]>
|
17 | 14 | */
|
18 |
| -if (interface_exists(ValueResolverInterface::class)) { |
19 |
| - final class BatchActionDtoResolver implements ValueResolverInterface |
20 |
| - { |
21 |
| - public function __construct( |
22 |
| - private readonly AdminContextProviderInterface $adminContextProvider, |
23 |
| - ) { |
24 |
| - } |
25 |
| - |
26 |
| - public function resolve(Request $request, ArgumentMetadata $argument): iterable |
27 |
| - { |
28 |
| - if (BatchActionDto::class !== $argument->getType()) { |
29 |
| - return []; |
30 |
| - } |
31 |
| - |
32 |
| - if (null === $context = $this->adminContextProvider->getContext()) { |
33 |
| - throw new \RuntimeException(sprintf('Some of your controller actions have type-hinted an argument with the "%s" class but that\'s only available for actions run to serve EasyAdmin requests. Remove the type-hint or make sure the action is part of an EasyAdmin request.', BatchActionDto::class)); |
34 |
| - } |
35 |
| - |
36 |
| - yield new BatchActionDto( |
37 |
| - $context->getRequest()->request->get(EA::BATCH_ACTION_NAME), |
38 |
| - $context->getRequest()->request->all()[EA::BATCH_ACTION_ENTITY_IDS] ?? [], |
39 |
| - $context->getRequest()->request->get(EA::ENTITY_FQCN), |
40 |
| - $context->getRequest()->request->get(EA::BATCH_ACTION_CSRF_TOKEN) |
41 |
| - ); |
42 |
| - } |
| 15 | +final class BatchActionDtoResolver implements ValueResolverInterface |
| 16 | +{ |
| 17 | + public function __construct( |
| 18 | + private readonly AdminContextProviderInterface $adminContextProvider, |
| 19 | + ) { |
43 | 20 | }
|
44 |
| -} else { |
45 |
| - final class BatchActionDtoResolver implements ArgumentValueResolverInterface |
46 |
| - { |
47 |
| - private AdminContextProvider $adminContextProvider; |
48 | 21 |
|
49 |
| - public function __construct(AdminContextProviderInterface $adminContextProvider, AdminUrlGeneratorInterface $adminUrlGenerator) |
50 |
| - { |
51 |
| - $this->adminContextProvider = $adminContextProvider; |
52 |
| - $this->adminUrlGenerator = $adminUrlGenerator; |
| 22 | + public function resolve(Request $request, ArgumentMetadata $argument): iterable |
| 23 | + { |
| 24 | + if (BatchActionDto::class !== $argument->getType()) { |
| 25 | + return []; |
53 | 26 | }
|
54 | 27 |
|
55 |
| - public function supports(Request $request, ArgumentMetadata $argument): bool |
56 |
| - { |
57 |
| - return BatchActionDto::class === $argument->getType(); |
| 28 | + if (null === $context = $this->adminContextProvider->getContext()) { |
| 29 | + throw new \RuntimeException(sprintf('Some of your controller actions have type-hinted an argument with the "%s" class but that\'s only available for actions run to serve EasyAdmin requests. Remove the type-hint or make sure the action is part of an EasyAdmin request.', BatchActionDto::class)); |
58 | 30 | }
|
59 | 31 |
|
60 |
| - public function resolve(Request $request, ArgumentMetadata $argument): iterable |
61 |
| - { |
62 |
| - if (null === $context = $this->adminContextProvider->getContext()) { |
63 |
| - throw new \RuntimeException(sprintf('Some of your controller actions have type-hinted an argument with the "%s" class but that\'s only available for actions run to serve EasyAdmin requests. Remove the type-hint or make sure the action is part of an EasyAdmin request.', BatchActionDto::class)); |
64 |
| - } |
65 |
| - |
66 |
| - yield new BatchActionDto( |
67 |
| - $context->getRequest()->request->get(EA::BATCH_ACTION_NAME), |
68 |
| - $context->getRequest()->request->all()[EA::BATCH_ACTION_ENTITY_IDS] ?? [], |
69 |
| - $context->getRequest()->request->get(EA::ENTITY_FQCN), |
70 |
| - $context->getRequest()->request->get(EA::BATCH_ACTION_CSRF_TOKEN) |
71 |
| - ); |
72 |
| - } |
| 32 | + yield new BatchActionDto( |
| 33 | + $context->getRequest()->request->get(EA::BATCH_ACTION_NAME), |
| 34 | + $context->getRequest()->request->all()[EA::BATCH_ACTION_ENTITY_IDS] ?? [], |
| 35 | + $context->getRequest()->request->get(EA::ENTITY_FQCN), |
| 36 | + $context->getRequest()->request->get(EA::BATCH_ACTION_CSRF_TOKEN) |
| 37 | + ); |
73 | 38 | }
|
74 | 39 | }
|
0 commit comments