src/Controller/ProductController.php line 39

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Controller;
  4. use Exception;
  5. use Sylius\Bundle\ResourceBundle\Controller\ResourceController;
  6. use Sylius\Component\Resource\ResourceActions;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. class ProductController extends ResourceController
  10. {
  11.     public function searchAction(Request $request): Response
  12.     {
  13.         try {
  14.             $configuration $this->requestConfigurationFactory->create($this->metadata$request);
  15.             $resources $this->resourcesCollectionProvider->get($configuration$this->repository);
  16.         }
  17.         catch (Exception $exception) {
  18.             throw $this->createNotFoundException();
  19.         }
  20.         $this->isGrantedOr403($configuration"search");
  21.         if ($configuration->isHtmlRequest()) {
  22.             return $this->render($configuration->getTemplate('product/search.html'), [
  23.                 'configuration'                  => $configuration,
  24.                 'metadata'                       => $this->metadata,
  25.                 'resources'                      => $resources,
  26.                 $this->metadata->getPluralName() => $resources,
  27.             ]);
  28.         }
  29.         throw $this->createNotFoundException();
  30.     }
  31.     public function indexAction(Request $request): Response
  32.     {
  33.         $configuration $this->requestConfigurationFactory->create($this->metadata$request);
  34.         $this->isGrantedOr403($configurationResourceActions::INDEX);
  35.         $resources $this->resourcesCollectionProvider->get($configuration$this->repository);
  36.         $this->eventDispatcher->dispatchMultiple(ResourceActions::INDEX$configuration$resources);
  37.         if ($configuration->isHtmlRequest()) {
  38.             return $this->render($configuration->getTemplate(ResourceActions::INDEX '.html'), [
  39.                 'configuration'                  => $configuration,
  40.                 'metadata'                       => $this->metadata,
  41.                 'resources'                      => $resources,
  42.                 $this->metadata->getPluralName() => $resources,
  43.             ]);
  44.         }
  45.         return $this->createRestView($configuration$resources);
  46.     }
  47. }