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