Skip to content

Instantly share code, notes, and snippets.

@kurozumi
Created January 2, 2021 05:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurozumi/0c83187eb56b84bbe16ab9d87a47654c to your computer and use it in GitHub Desktop.
Save kurozumi/0c83187eb56b84bbe16ab9d87a47654c to your computer and use it in GitHub Desktop.
ProductValueResolver
<?php
namespace Customize\ArgumentResolver;
use Eccube\Entity\Product;
use Eccube\Repository\ProductRepository;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
class ProductValueResolver implements ArgumentValueResolverInterface
{
/**
* @var ProductRepository
*/
private $productRepository;
public function __construct(ProductRepository $productRepository)
{
$this->productRepository = $productRepository;
}
public function supports(Request $request, ArgumentMetadata $argument)
{
return Product::class === $argument->getType();
}
public function resolve(Request $request, ArgumentMetadata $argument)
{
$id = $request->attributes->get('id');
yield $this->productRepository->findWithSortedClassCategories($id);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment