for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.shop and write us
* an email on [email protected].
*/
declare(strict_types=1);
namespace BitBag\SyliusCmsPlugin\Controller\Action\Admin;
use BitBag\SyliusCmsPlugin\Repository\ProductRepositoryInterface;
use FOS\RestBundle\View\View;
use FOS\RestBundle\View\ViewHandler;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
final class ProductSearchAction
{
/**
* @var ProductRepositoryInterface
private $productRepository;
* @var ViewHandler
private $viewHandler;
* @param ProductRepositoryInterface $productRepository
* @param ViewHandler $viewHandler
public function __construct(ProductRepositoryInterface $productRepository, ViewHandler $viewHandler)
$this->productRepository = $productRepository;
$this->viewHandler = $viewHandler;
}
* @param Request $request
*
* @return Response
public function __invoke(Request $request): Response
$resource = $this->productRepository->findByNamePart($request->get('phrase', ''));
$view = View::create($resource);
$this->viewHandler->setExclusionStrategyGroups(['Autocomplete']);
$view->getContext()->enableMaxDepth();
return $this->viewHandler->handle($view);