Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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