vendor/sulu/sulu/src/Sulu/Bundle/WebsiteBundle/Sitemap/SitemapProviderPool.php line 60

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of Sulu.
  4.  *
  5.  * (c) Sulu GmbH
  6.  *
  7.  * This source file is subject to the MIT license that is bundled
  8.  * with this source code in the file LICENSE.
  9.  */
  10. namespace Sulu\Bundle\WebsiteBundle\Sitemap;
  11. use Sulu\Bundle\WebsiteBundle\Exception\SitemapProviderNotFoundException;
  12. /**
  13.  * Pool of all sitemap-providers.
  14.  */
  15. class SitemapProviderPool implements SitemapProviderPoolInterface
  16. {
  17.     /**
  18.      * @var SitemapProviderInterface[]
  19.      */
  20.     private $providers;
  21.     /**
  22.      * @var Sitemap[]
  23.      */
  24.     private $index;
  25.     /**
  26.      * @param SitemapProviderInterface[] $providers
  27.      */
  28.     public function __construct(iterable $providers)
  29.     {
  30.         foreach ($providers as $provider) {
  31.             $this->providers[$provider->getAlias()] = $provider;
  32.         }
  33.     }
  34.     public function getProvider($alias)
  35.     {
  36.         if (!$this->hasProvider($alias)) {
  37.             throw new SitemapProviderNotFoundException($alias, \array_keys($this->providers));
  38.         }
  39.         return $this->providers[$alias];
  40.     }
  41.     public function getProviders()
  42.     {
  43.         return $this->providers;
  44.     }
  45.     public function hasProvider($alias)
  46.     {
  47.         return \array_key_exists($alias$this->providers);
  48.     }
  49.     public function getIndex($scheme$host)
  50.     {
  51.         if ($this->index) {
  52.             return $this->index;
  53.         }
  54.         $this->index = [];
  55.         foreach ($this->providers as $alias => $provider) {
  56.             $this->index[] = $provider->createSitemap($scheme$host);
  57.         }
  58.         return $this->index;
  59.     }
  60. }