vendor/sylius/resource-bundle/src/Bundle/Grid/Controller/ResourcesResolver.php line 55

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of the Sylius package.
  4. *
  5. * (c) Paweł Jędrzejewski
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. declare(strict_types=1);
  11. namespace Sylius\Bundle\ResourceBundle\Grid\Controller;
  12. use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration;
  13. use Sylius\Bundle\ResourceBundle\Controller\ResourcesResolverInterface;
  14. use Sylius\Bundle\ResourceBundle\Grid\View\ResourceGridViewFactoryInterface;
  15. use Sylius\Component\Grid\Parameters;
  16. use Sylius\Component\Grid\Provider\GridProviderInterface;
  17. use Sylius\Component\Resource\Repository\RepositoryInterface;
  18. final class ResourcesResolver implements ResourcesResolverInterface
  19. {
  20. private ResourcesResolverInterface $decoratedResolver;
  21. private GridProviderInterface $gridProvider;
  22. private ResourceGridViewFactoryInterface $gridViewFactory;
  23. public function __construct(
  24. ResourcesResolverInterface $decoratedResolver,
  25. GridProviderInterface $gridProvider,
  26. ResourceGridViewFactoryInterface $gridViewFactory,
  27. ) {
  28. $this->decoratedResolver = $decoratedResolver;
  29. $this->gridProvider = $gridProvider;
  30. $this->gridViewFactory = $gridViewFactory;
  31. }
  32. /**
  33. * @psalm-suppress MissingReturnType
  34. */
  35. public function getResources(RequestConfiguration $requestConfiguration, RepositoryInterface $repository)
  36. {
  37. if (!$requestConfiguration->hasGrid()) {
  38. return $this->decoratedResolver->getResources($requestConfiguration, $repository);
  39. }
  40. $gridDefinition = $this->gridProvider->get($requestConfiguration->getGrid());
  41. $request = $requestConfiguration->getRequest();
  42. $parameters = new Parameters($request->query->all());
  43. $gridView = $this->gridViewFactory->create($gridDefinition, $parameters, $requestConfiguration->getMetadata(), $requestConfiguration);
  44. if ($requestConfiguration->isHtmlRequest()) {
  45. return $gridView;
  46. }
  47. return $gridView->getData();
  48. }
  49. }