vendor/lightsaml2/lightsaml/src/LightSaml/Store/EntityDescriptor/FileEntityDescriptorStore.php line 71

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\Error\LightSamlXmlException;
  12. use LightSaml\Model\Metadata\EntitiesDescriptor;
  13. use LightSaml\Model\Metadata\EntityDescriptor;
  14. class FileEntityDescriptorStore implements EntityDescriptorStoreInterface
  15. {
  16.     private $filename;
  17.     /** @var EntityDescriptor|EntitiesDescriptor */
  18.     private $object;
  19.     /**
  20.      * @param string $filename
  21.      */
  22.     public function __construct($filename)
  23.     {
  24.         $this->filename $filename;
  25.     }
  26.     /**
  27.      * @param string $entityId
  28.      *
  29.      * @return EntityDescriptor|null
  30.      */
  31.     public function get($entityId)
  32.     {
  33.         if (null == $this->object) {
  34.             $this->load();
  35.         }
  36.         if ($this->object instanceof EntityDescriptor) {
  37.             if ($this->object->getEntityID() == $entityId) {
  38.                 return $this->object;
  39.             } else {
  40.                 return null;
  41.             }
  42.         } else {
  43.             return $this->object->getByEntityId($entityId);
  44.         }
  45.     }
  46.     /**
  47.      * @param string $entityId
  48.      *
  49.      * @return bool
  50.      */
  51.     public function has($entityId)
  52.     {
  53.         return null != $this->get($entityId);
  54.     }
  55.     /**
  56.      * @return array|EntityDescriptor[]
  57.      */
  58.     public function all()
  59.     {
  60.         if (null == $this->object) {
  61.             $this->load();
  62.         }
  63.         if ($this->object instanceof EntityDescriptor) {
  64.             return [$this->object];
  65.         } else {
  66.             return $this->object->getAllEntityDescriptors();
  67.         }
  68.     }
  69.     private function load()
  70.     {
  71.         try {
  72.             $this->object EntityDescriptor::load($this->filename);
  73.         } catch (LightSamlXmlException $ex) {
  74.             $this->object EntitiesDescriptor::load($this->filename);
  75.         }
  76.     }
  77. }