Skip to content

Commit

Permalink
minor #5454 Add compatibility with ValueResolverInterface (javieregui…
Browse files Browse the repository at this point in the history
…luz)

This PR was squashed before being merged into the 4.x branch.

Discussion
----------

Add compatibility with ValueResolverInterface

This avoids a deprecation when upgrading to Symfony 6.2. See symfony/symfony#47363

Commits
-------

497b39c Add compatibility with ValueResolverInterface
  • Loading branch information
javiereguiluz committed Nov 25, 2022
2 parents 4d0bbbe + 497b39c commit 85d0d02
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/ArgumentResolver/AdminContextResolver.php
Expand Up @@ -5,13 +5,12 @@
use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext;
use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;

/**
/*
* @author Javier Eguiluz <javier.eguiluz@gmail.com>
*/
final class AdminContextResolver implements ArgumentValueResolverInterface
final class AdminContextResolver implements CompatValueResolverInterface
{
private AdminContextProvider $adminContextProvider;

Expand All @@ -27,6 +26,10 @@ public function supports(Request $request, ArgumentMetadata $argument): bool

public function resolve(Request $request, ArgumentMetadata $argument): iterable
{
if (AdminContext::class !== $argument->getType()) {
return [];
}

yield $this->adminContextProvider->getContext();
}
}
9 changes: 6 additions & 3 deletions src/ArgumentResolver/BatchActionDtoResolver.php
Expand Up @@ -7,13 +7,12 @@
use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;

/**
/*
* @author Javier Eguiluz <javier.eguiluz@gmail.com>
*/
final class BatchActionDtoResolver implements ArgumentValueResolverInterface
final class BatchActionDtoResolver implements CompatValueResolverInterface
{
private AdminContextProvider $adminContextProvider;
private AdminUrlGenerator $adminUrlGenerator;
Expand All @@ -31,6 +30,10 @@ public function supports(Request $request, ArgumentMetadata $argument): bool

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));
}
Expand Down
13 changes: 13 additions & 0 deletions src/ArgumentResolver/CompatValueResolverInterface.php
@@ -0,0 +1,13 @@
<?php

namespace EasyCorp\Bundle\EasyAdminBundle\ArgumentResolver;

use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
use Symfony\Component\HttpKernel\Controller\ValueResolverInterface;

// TODO: remove this file when all supported Symfony versions include ValueResolverInterface
if (class_exists(ValueResolverInterface::class)) {
class_alias(ValueResolverInterface::class, CompatValueResolverInterface::class);
} else {
class_alias(ArgumentValueResolverInterface::class, CompatValueResolverInterface::class);
}

0 comments on commit 85d0d02

Please sign in to comment.