vendor/sylius/sylius/src/Sylius/Bundle/CoreBundle/SectionResolver/UriBasedSectionProvider.php line 36

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\CoreBundle\SectionResolver;
  12. use Symfony\Component\HttpFoundation\RequestStack;
  13. use Webmozart\Assert\Assert;
  14. final class UriBasedSectionProvider implements SectionProviderInterface
  15. {
  16.     /** @var RequestStack */
  17.     private $requestStack;
  18.     /** @var iterable|UriBasedSectionResolverInterface[] */
  19.     private $resolvers;
  20.     public function __construct(RequestStack $requestStackiterable $resolvers)
  21.     {
  22.         $this->requestStack $requestStack;
  23.         Assert::allIsInstanceOf($resolversUriBasedSectionResolverInterface::class);
  24.         $this->resolvers $resolvers;
  25.     }
  26.     public function getSection(): ?SectionInterface
  27.     {
  28.         $request $this->requestStack->getMasterRequest();
  29.         if (null === $request) {
  30.             return null;
  31.         }
  32.         $uri $request->getPathInfo();
  33.         foreach ($this->resolvers as $resolver) {
  34.             try {
  35.                 return $resolver->getSection($uri);
  36.             } catch (SectionCannotBeResolvedException $exception) {
  37.             }
  38.         }
  39.         return null;
  40.     }
  41. }