Skip to content

Commit 7244337

Browse files
committed
Create RelayStateTrait
1 parent da5c0c2 commit 7244337

File tree

5 files changed

+54
-30
lines changed

5 files changed

+54
-30
lines changed

src/Binding.php

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@
2525
*/
2626
abstract class Binding
2727
{
28-
/**
29-
* The RelayState associated with the message.
30-
*
31-
* @var string|null
32-
*/
33-
protected ?string $relayState = null;
34-
3528
/**
3629
* The destination of messages.
3730
*
@@ -156,29 +149,6 @@ public function getDestination(): ?string
156149
}
157150

158151

159-
/**
160-
* Set the RelayState associated with he message.
161-
*
162-
* @param string|null $relayState The RelayState.
163-
*/
164-
public function setRelayState(?string $relayState = null): void
165-
{
166-
Assert::nullOrValidRelayState($relayState);
167-
$this->relayState = $relayState;
168-
}
169-
170-
171-
/**
172-
* Get the RelayState associated with the message.
173-
*
174-
* @return string|null The RelayState.
175-
*/
176-
public function getRelayState(): ?string
177-
{
178-
return $this->relayState;
179-
}
180-
181-
182152
/**
183153
* Override the destination of a message.
184154
*

src/Binding/HTTPArtifact.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use SimpleSAML\Metadata\MetaDataStorageHandler;
1515
use SimpleSAML\Module\saml\Message as MSG;
1616
use SimpleSAML\SAML2\Binding;
17+
use SimpleSAML\SAML2\Binding\RelayStateTrait;
1718
use SimpleSAML\SAML2\SOAPClient;
1819
use SimpleSAML\SAML2\Utils;
1920
use SimpleSAML\SAML2\XML\saml\Issuer;
@@ -43,6 +44,8 @@
4344
*/
4445
class HTTPArtifact extends Binding
4546
{
47+
use RelayStateTrait;
48+
4649
/**
4750
* @psalm-suppress UndefinedDocblockClass
4851
* @psalm-suppress UndefinedClass

src/Binding/HTTPPost.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Psr\Http\Message\ServerRequestInterface;
1111
use SimpleSAML\Assert\Assert;
1212
use SimpleSAML\SAML2\Binding;
13+
use SimpleSAML\SAML2\Binding\RelayStateTrait;
1314
use SimpleSAML\SAML2\Exception\ProtocolViolationException;
1415
use SimpleSAML\SAML2\Utils;
1516
use SimpleSAML\SAML2\XML\samlp\AbstractMessage;
@@ -28,6 +29,8 @@
2829
*/
2930
class HTTPPost extends Binding
3031
{
32+
use RelayStateTrait;
33+
3134
/**
3235
* Send a SAML 2 message using the HTTP-POST binding.
3336
*

src/Binding/HTTPRedirect.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Psr\Http\Message\ServerRequestInterface;
1111
use SimpleSAML\Assert\Assert;
1212
use SimpleSAML\SAML2\Binding;
13+
use SimpleSAML\SAML2\Binding\RelayStateTrait;
1314
use SimpleSAML\SAML2\Compat\ContainerSingleton;
1415
use SimpleSAML\SAML2\Constants as C;
1516
use SimpleSAML\SAML2\Exception\ProtocolViolationException;
@@ -39,6 +40,8 @@
3940
*/
4041
class HTTPRedirect extends Binding
4142
{
43+
use RelayStateTrait;
44+
4245
/**
4346
* Create the redirect URL for a message.
4447
*

src/Binding/RelayStateTrait.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\SAML2\Binding;
6+
7+
use SimpleSAML\SAML2\Assert\Assert;
8+
9+
/**
10+
* Trait grouping common functionality for binding that use a RelayState.
11+
*
12+
* @package simplesamlphp/saml2
13+
*/
14+
trait RelayStateTrait
15+
{
16+
/**
17+
* The relay state.
18+
*
19+
* @var string|null
20+
*/
21+
protected ?string $relayState = null;
22+
23+
24+
/**
25+
* Set the RelayState associated with he message.
26+
*
27+
* @param string|null $relayState The RelayState.
28+
*/
29+
public function setRelayState(?string $relayState = null): void
30+
{
31+
Assert::nullOrValidRelayState($relayState);
32+
$this->relayState = $relayState;
33+
}
34+
35+
36+
/**
37+
* Get the RelayState associated with the message.
38+
*
39+
* @return string|null The RelayState.
40+
*/
41+
public function getRelayState(): ?string
42+
{
43+
return $this->relayState;
44+
}
45+
}

0 commit comments

Comments
 (0)