Created
January 2, 2021 05:36
-
-
Save kurozumi/0c83187eb56b84bbe16ab9d87a47654c to your computer and use it in GitHub Desktop.
ProductValueResolver
This file contains hidden or 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
<?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