/
TransformerChain.php
62 lines (49 loc) · 1.75 KB
/
TransformerChain.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
declare(strict_types=1);
namespace SimpleSAML\SAML2\Assertion\Transformer;
use SimpleSAML\SAML2\XML\saml\Assertion;
use SimpleSAML\SAML2\Configuration\IdentityProvider;
use SimpleSAML\SAML2\Configuration\IdentityProviderAware;
use SimpleSAML\SAML2\Configuration\ServiceProvider;
use SimpleSAML\SAML2\Configuration\ServiceProviderAware;
class TransformerChain implements TransformerInterface
{
/** @var \SimpleSAML\SAML2\Assertion\Transformer\TransformerInterface[] */
private $transformers = [];
/**
* Constructor for TransformerChain
*
* @param \SimpleSAML\SAML2\Configuration\IdentityProvider $identityProvider
* @param \SimpleSAML\SAML2\Configuration\ServiceProvider $serviceProvider
*/
public function __construct(
private IdentityProvider $identityProvider,
private ServiceProvider $serviceProvider,
) {
}
/**
* @param \SimpleSAML\SAML2\Assertion\Transformer\TransformerInterface $transformer
*/
public function addTransformerStep(TransformerInterface $transformer): void
{
if ($transformer instanceof IdentityProviderAware) {
$transformer->setIdentityProvider($this->identityProvider);
}
if ($transformer instanceof ServiceProviderAware) {
$transformer->setServiceProvider($this->serviceProvider);
}
$this->transformers[] = $transformer;
}
/**
* @param \SimpleSAML\SAML2\XML\saml\Assertion $assertion
*
* @return \SimpleSAML\SAML2\XML\saml\Assertion
*/
public function transform(Assertion $assertion): Assertion
{
foreach ($this->transformers as $transformer) {
$assertion = $transformer->transform($assertion);
}
return $assertion;
}
}