-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3b20674
commit 65f2320
Showing
2 changed files
with
100 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,22 +12,43 @@ | |
/* | ||
* @author Javier Eguiluz <[email protected]> | ||
*/ | ||
final class AdminContextResolver implements ArgumentValueResolverInterface, ValueResolverInterface | ||
{ | ||
private AdminContextProvider $adminContextProvider; | ||
|
||
public function __construct(AdminContextProvider $adminContextProvider) | ||
if (interface_exists(ValueResolverInterface::class)) { | ||
final class AdminContextResolver implements ValueResolverInterface | ||
{ | ||
$this->adminContextProvider = $adminContextProvider; | ||
} | ||
private AdminContextProvider $adminContextProvider; | ||
|
||
public function supports(Request $request, ArgumentMetadata $argument): bool | ||
{ | ||
return AdminContext::class === $argument->getType(); | ||
} | ||
public function __construct(AdminContextProvider $adminContextProvider) | ||
{ | ||
$this->adminContextProvider = $adminContextProvider; | ||
} | ||
|
||
public function resolve(Request $request, ArgumentMetadata $argument): iterable | ||
{ | ||
if (AdminContext::class !== $argument->getType()) { | ||
return []; | ||
} | ||
|
||
public function resolve(Request $request, ArgumentMetadata $argument): iterable | ||
yield $this->adminContextProvider->getContext(); | ||
} | ||
} | ||
} else { | ||
final class AdminContextResolver implements ArgumentValueResolverInterface | ||
Check failure on line 35 in src/ArgumentResolver/AdminContextResolver.php GitHub Actions / phpstan
|
||
{ | ||
yield $this->adminContextProvider->getContext(); | ||
private AdminContextProvider $adminContextProvider; | ||
|
||
public function __construct(AdminContextProvider $adminContextProvider) | ||
{ | ||
$this->adminContextProvider = $adminContextProvider; | ||
} | ||
|
||
public function supports(Request $request, ArgumentMetadata $argument): bool | ||
{ | ||
return AdminContext::class === $argument->getType(); | ||
} | ||
|
||
public function resolve(Request $request, ArgumentMetadata $argument): iterable | ||
{ | ||
yield $this->adminContextProvider->getContext(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,39 +14,77 @@ | |
/* | ||
* @author Javier Eguiluz <[email protected]> | ||
*/ | ||
final class BatchActionDtoResolver implements ArgumentValueResolverInterface, ValueResolverInterface | ||
{ | ||
private AdminContextProvider $adminContextProvider; | ||
private AdminUrlGeneratorInterface $adminUrlGenerator; | ||
|
||
public function __construct(AdminContextProvider $adminContextProvider, AdminUrlGeneratorInterface $adminUrlGenerator) | ||
if (interface_exists(ValueResolverInterface::class)) { | ||
final class BatchActionDtoResolver implements ValueResolverInterface | ||
{ | ||
$this->adminContextProvider = $adminContextProvider; | ||
$this->adminUrlGenerator = $adminUrlGenerator; | ||
} | ||
private AdminContextProvider $adminContextProvider; | ||
private AdminUrlGeneratorInterface $adminUrlGenerator; | ||
|
||
public function supports(Request $request, ArgumentMetadata $argument): bool | ||
{ | ||
return BatchActionDto::class === $argument->getType(); | ||
} | ||
public function __construct(AdminContextProvider $adminContextProvider, AdminUrlGeneratorInterface $adminUrlGenerator) | ||
{ | ||
$this->adminContextProvider = $adminContextProvider; | ||
$this->adminUrlGenerator = $adminUrlGenerator; | ||
} | ||
|
||
public function resolve(Request $request, ArgumentMetadata $argument): iterable | ||
{ | ||
if (BatchActionDto::class !== $argument->getType()) { | ||
return []; | ||
} | ||
|
||
if (null === $context = $this->adminContextProvider->getContext()) { | ||
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)); | ||
} | ||
|
||
$batchActionUrl = $context->getRequest()->request->get(EA::BATCH_ACTION_URL); | ||
$batchActionUrlQueryString = parse_url($batchActionUrl, \PHP_URL_QUERY); | ||
parse_str($batchActionUrlQueryString, $batchActionUrlParts); | ||
$referrerUrl = $batchActionUrlParts[EA::REFERRER] ?? $this->adminUrlGenerator->unsetAll()->generateUrl(); | ||
|
||
public function resolve(Request $request, ArgumentMetadata $argument): iterable | ||
yield new BatchActionDto( | ||
$context->getRequest()->request->get(EA::BATCH_ACTION_NAME), | ||
$context->getRequest()->request->all()[EA::BATCH_ACTION_ENTITY_IDS] ?? [], | ||
$context->getRequest()->request->get(EA::ENTITY_FQCN), | ||
$referrerUrl, | ||
$context->getRequest()->request->get(EA::BATCH_ACTION_CSRF_TOKEN) | ||
); | ||
} | ||
} | ||
} else { | ||
final class BatchActionDtoResolver implements ArgumentValueResolverInterface | ||
Check failure on line 54 in src/ArgumentResolver/BatchActionDtoResolver.php GitHub Actions / phpstan
|
||
{ | ||
if (null === $context = $this->adminContextProvider->getContext()) { | ||
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)); | ||
private AdminContextProvider $adminContextProvider; | ||
private AdminUrlGeneratorInterface $adminUrlGenerator; | ||
|
||
public function __construct(AdminContextProvider $adminContextProvider, AdminUrlGeneratorInterface $adminUrlGenerator) | ||
{ | ||
$this->adminContextProvider = $adminContextProvider; | ||
$this->adminUrlGenerator = $adminUrlGenerator; | ||
} | ||
|
||
public function supports(Request $request, ArgumentMetadata $argument): bool | ||
{ | ||
return BatchActionDto::class === $argument->getType(); | ||
} | ||
|
||
$batchActionUrl = $context->getRequest()->request->get(EA::BATCH_ACTION_URL); | ||
$batchActionUrlQueryString = parse_url($batchActionUrl, \PHP_URL_QUERY); | ||
parse_str($batchActionUrlQueryString, $batchActionUrlParts); | ||
$referrerUrl = $batchActionUrlParts[EA::REFERRER] ?? $this->adminUrlGenerator->unsetAll()->generateUrl(); | ||
|
||
yield new BatchActionDto( | ||
$context->getRequest()->request->get(EA::BATCH_ACTION_NAME), | ||
$context->getRequest()->request->all()[EA::BATCH_ACTION_ENTITY_IDS] ?? [], | ||
$context->getRequest()->request->get(EA::ENTITY_FQCN), | ||
$referrerUrl, | ||
$context->getRequest()->request->get(EA::BATCH_ACTION_CSRF_TOKEN) | ||
); | ||
public function resolve(Request $request, ArgumentMetadata $argument): iterable | ||
{ | ||
if (null === $context = $this->adminContextProvider->getContext()) { | ||
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)); | ||
} | ||
|
||
$batchActionUrl = $context->getRequest()->request->get(EA::BATCH_ACTION_URL); | ||
$batchActionUrlQueryString = parse_url($batchActionUrl, \PHP_URL_QUERY); | ||
parse_str($batchActionUrlQueryString, $batchActionUrlParts); | ||
$referrerUrl = $batchActionUrlParts[EA::REFERRER] ?? $this->adminUrlGenerator->unsetAll()->generateUrl(); | ||
|
||
yield new BatchActionDto( | ||
$context->getRequest()->request->get(EA::BATCH_ACTION_NAME), | ||
$context->getRequest()->request->all()[EA::BATCH_ACTION_ENTITY_IDS] ?? [], | ||
$context->getRequest()->request->get(EA::ENTITY_FQCN), | ||
$referrerUrl, | ||
$context->getRequest()->request->get(EA::BATCH_ACTION_CSRF_TOKEN) | ||
); | ||
} | ||
} | ||
} |