1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace drupol\CasBundle\Configuration; |
6
|
|
|
|
7
|
|
|
use drupol\psrcas\Configuration\Properties as PsrCasConfiguration; |
8
|
|
|
use drupol\psrcas\Configuration\PropertiesInterface; |
9
|
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
10
|
|
|
use Symfony\Component\Routing\RouterInterface; |
11
|
|
|
|
12
|
|
|
use const FILTER_VALIDATE_URL; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class Symfony. |
16
|
|
|
*/ |
17
|
|
|
final class Symfony implements PropertiesInterface |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var \drupol\psrcas\Configuration\Properties |
21
|
|
|
*/ |
22
|
|
|
private $cas; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var \Symfony\Component\Routing\RouterInterface |
26
|
|
|
*/ |
27
|
|
|
private $router; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Symfony constructor. |
31
|
|
|
* |
32
|
|
|
* @param array<string, mixed> $properties |
33
|
|
|
* @param \Symfony\Component\Routing\RouterInterface $router |
34
|
|
|
*/ |
35
|
3 |
|
public function __construct(array $properties, RouterInterface $router) |
36
|
|
|
{ |
37
|
3 |
|
$this->router = $router; |
38
|
3 |
|
$this->cas = new PsrCasConfiguration($this->routeToUrl($properties)); |
39
|
3 |
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
*/ |
44
|
1 |
|
public function all(): array |
45
|
|
|
{ |
46
|
1 |
|
return $this->cas->all(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param mixed $offset |
51
|
|
|
* |
52
|
|
|
* @return bool |
53
|
|
|
*/ |
54
|
1 |
|
public function offsetExists($offset) |
55
|
|
|
{ |
56
|
1 |
|
return $this->cas->offsetExists($offset); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param mixed $offset |
61
|
|
|
* |
62
|
|
|
* @return array<string, mixed>|mixed |
63
|
|
|
*/ |
64
|
1 |
|
public function offsetGet($offset) |
65
|
|
|
{ |
66
|
1 |
|
return $this->cas->offsetGet($offset); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param mixed $offset |
71
|
|
|
* @param mixed $value |
72
|
|
|
*/ |
73
|
1 |
|
public function offsetSet($offset, $value): void |
74
|
|
|
{ |
75
|
1 |
|
$this->cas->offsetSet($offset, $value); |
76
|
1 |
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param mixed $offset |
80
|
|
|
*/ |
81
|
1 |
|
public function offsetUnset($offset): void |
82
|
|
|
{ |
83
|
1 |
|
$this->cas->offsetUnset($offset); |
84
|
1 |
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Transform Symfony routes into absolute URLs. |
88
|
|
|
* |
89
|
|
|
* @param array<string, mixed> $properties |
90
|
|
|
* The properties. |
91
|
|
|
* |
92
|
|
|
* @return array<string, mixed> |
93
|
|
|
* The updated properties. |
94
|
|
|
*/ |
95
|
3 |
|
private function routeToUrl(array $properties): array |
96
|
|
|
{ |
97
|
3 |
|
$properties = $this->updateDefaultParameterRouteToUrl( |
98
|
3 |
|
$properties, |
99
|
3 |
|
'pgtUrl' |
100
|
|
|
); |
101
|
|
|
|
102
|
3 |
|
return $this->updateDefaultParameterRouteToUrl( |
103
|
3 |
|
$properties, |
104
|
3 |
|
'service' |
105
|
|
|
); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @param array<string, mixed> $properties |
110
|
|
|
* @param string $key |
111
|
|
|
* |
112
|
|
|
* @return array<string, mixed> |
113
|
|
|
*/ |
114
|
3 |
|
private function updateDefaultParameterRouteToUrl(array $properties, string $key): array |
115
|
|
|
{ |
116
|
3 |
|
foreach ($properties['protocol'] as $protocolKey => $protocol) { |
117
|
3 |
|
if (false === isset($protocol['default_parameters'][$key])) { |
118
|
3 |
|
continue; |
119
|
|
|
} |
120
|
|
|
|
121
|
3 |
|
$route = $protocol['default_parameters'][$key]; |
122
|
|
|
|
123
|
3 |
|
if (false === filter_var($route, FILTER_VALIDATE_URL)) { |
124
|
|
|
$route = $this |
125
|
3 |
|
->router |
126
|
3 |
|
->generate( |
127
|
3 |
|
$route, |
128
|
3 |
|
[], |
129
|
3 |
|
UrlGeneratorInterface::ABSOLUTE_URL |
130
|
|
|
); |
131
|
|
|
|
132
|
3 |
|
$properties['protocol'][$protocolKey]['default_parameters'][$key] = $route; |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|
136
|
3 |
|
return $properties; |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|