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

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 iterable|UriBasedSectionResolverInterface[] */
  17.     private iterable $resolvers;
  18.     public function __construct(private RequestStack $requestStackiterable $resolvers)
  19.     {
  20.         Assert::allIsInstanceOf($resolversUriBasedSectionResolverInterface::class);
  21.         $this->resolvers $resolvers;
  22.     }
  23.     public function getSection(): ?SectionInterface
  24.     {
  25.         $request $this->requestStack->getMasterRequest();
  26.         if (null === $request) {
  27.             return null;
  28.         }
  29.         $uri $request->getPathInfo();
  30.         foreach ($this->resolvers as $resolver) {
  31.             try {
  32.                 return $resolver->getSection($uri);
  33.             } catch (SectionCannotBeResolvedException) {
  34.             }
  35.         }
  36.         return null;
  37.     }
  38. }