CustomUrlLocator.php 874 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\UrlRewriteGraphQl\Model\Resolver\UrlRewrite;
  8. /**
  9. * Pool of custom URL locators.
  10. */
  11. class CustomUrlLocator implements CustomUrlLocatorInterface
  12. {
  13. /**
  14. * @var CustomUrlLocatorInterface[]
  15. */
  16. private $urlLocators;
  17. /**
  18. * @param CustomUrlLocatorInterface[] $urlLocators
  19. */
  20. public function __construct(array $urlLocators = [])
  21. {
  22. $this->urlLocators = $urlLocators;
  23. }
  24. /**
  25. * @inheritdoc
  26. */
  27. public function locateUrl($urlKey): ?string
  28. {
  29. foreach ($this->urlLocators as $urlLocator) {
  30. $url = $urlLocator->locateUrl($urlKey);
  31. if ($url !== null) {
  32. return $url;
  33. }
  34. }
  35. return null;
  36. }
  37. }