vendor/lightsaml2/lightsaml/src/LightSaml/Store/EntityDescriptor/CompositeEntityDescriptorStore.php line 81

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the LightSAML-Core package.
  4.  *
  5.  * (c) Milos Tomic <tmilos@lightsaml.com>
  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 LightSaml\Store\EntityDescriptor;
  11. use LightSaml\Model\Metadata\EntityDescriptor;
  12. class CompositeEntityDescriptorStore implements EntityDescriptorStoreInterface
  13. {
  14.     /** @var EntityDescriptorStoreInterface[] */
  15.     private $children = [];
  16.     /**
  17.      * @param EntityDescriptorStoreInterface[] $stores
  18.      */
  19.     public function __construct(array $stores = [])
  20.     {
  21.         foreach ($stores as $store) {
  22.             $this->add($store);
  23.         }
  24.     }
  25.     /**
  26.      * @return CompositeEntityDescriptorStore This instance
  27.      */
  28.     public function add(EntityDescriptorStoreInterface $store)
  29.     {
  30.         $this->children[] = $store;
  31.         return $this;
  32.     }
  33.     /**
  34.      * @param string $entityId
  35.      *
  36.      * @return EntityDescriptor|null
  37.      */
  38.     public function get($entityId)
  39.     {
  40.         foreach ($this->children as $store) {
  41.             $result $store->get($entityId);
  42.             if ($result) {
  43.                 return $result;
  44.             }
  45.         }
  46.         return null;
  47.     }
  48.     /**
  49.      * @param string $entityId
  50.      *
  51.      * @return bool
  52.      */
  53.     public function has($entityId)
  54.     {
  55.         foreach ($this->children as $store) {
  56.             if ($store->has($entityId)) {
  57.                 return true;
  58.             }
  59.         }
  60.         return false;
  61.     }
  62.     /**
  63.      * @return array|EntityDescriptor[]
  64.      */
  65.     public function all()
  66.     {
  67.         $result = [];
  68.         foreach ($this->children as $store) {
  69.             $result array_merge($result$store->all());
  70.         }
  71.         return $result;
  72.     }
  73. }