|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AerialShip\SamlSPBundle\Config; |
|
4
|
|
|
|
|
5
|
|
|
use AerialShip\LightSaml\Model\Metadata\EntitiesDescriptor; |
|
6
|
|
|
use AerialShip\LightSaml\Model\Metadata\EntityDescriptor; |
|
7
|
|
|
use Symfony\Component\HttpKernel\KernelInterface; |
|
8
|
|
|
|
|
9
|
|
|
class EntityDescriptorFileProvider implements EntityDescriptorProviderInterface |
|
10
|
|
|
{ |
|
11
|
|
|
/** @var KernelInterface */ |
|
12
|
|
|
protected $kernel; |
|
13
|
|
|
|
|
14
|
|
|
/** @var string */ |
|
15
|
|
|
protected $filename; |
|
16
|
|
|
|
|
17
|
|
|
/** @var string|null */ |
|
18
|
|
|
protected $entityId; |
|
19
|
|
|
|
|
20
|
|
|
/** @var EntityDescriptor|null */ |
|
21
|
|
|
private $entityDescriptor; |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
function __construct(KernelInterface $kernel) |
|
|
|
|
|
|
26
|
|
|
{ |
|
27
|
|
|
$this->kernel = $kernel; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param string $filename |
|
33
|
|
|
* @throws \InvalidArgumentException |
|
34
|
|
|
*/ |
|
35
|
|
|
public function setFilename($filename) |
|
36
|
|
|
{ |
|
37
|
|
|
if ($filename && $filename[0] == '@') { |
|
38
|
|
|
$filename = $this->kernel->locateResource($filename); |
|
39
|
|
|
} |
|
40
|
|
|
if (!is_file($filename)) { |
|
41
|
|
|
throw new \InvalidArgumentException('Specified file does not exist: '.$filename); |
|
42
|
|
|
} |
|
43
|
|
|
$this->filename = $filename; |
|
|
|
|
|
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return string |
|
48
|
|
|
*/ |
|
49
|
|
|
public function getFilename() |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->filename; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param null|string $entityId |
|
56
|
|
|
*/ |
|
57
|
|
|
public function setEntityId($entityId) |
|
58
|
|
|
{ |
|
59
|
|
|
$this->entityId = $entityId; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @return null|string |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getEntityId() |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->entityId; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @return EntityDescriptor |
|
75
|
|
|
*/ |
|
76
|
|
|
public function getEntityDescriptor() |
|
77
|
|
|
{ |
|
78
|
|
|
if ($this->entityDescriptor === null) { |
|
79
|
|
|
$this->load(); |
|
80
|
|
|
} |
|
81
|
|
|
return $this->entityDescriptor; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
|
|
85
|
|
|
protected function load() |
|
86
|
|
|
{ |
|
87
|
|
|
$doc = new \DOMDocument(); |
|
88
|
|
|
$doc->load($this->filename); |
|
89
|
|
|
if ($this->entityId) { |
|
|
|
|
|
|
90
|
|
|
$entitiesDescriptor = new EntitiesDescriptor(); |
|
91
|
|
|
$entitiesDescriptor->loadFromXml($doc->firstChild); |
|
|
|
|
|
|
92
|
|
|
$this->entityDescriptor = $entitiesDescriptor->getByEntityId($this->entityId); |
|
93
|
|
|
} else { |
|
94
|
|
|
$this->entityDescriptor = new EntityDescriptor(); |
|
95
|
|
|
$this->entityDescriptor->loadFromXml($doc->firstChild); |
|
|
|
|
|
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.