|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace SimpleSAML\Test\SAML2; |
| 6 | + |
| 7 | +use SimpleSAML\SAML2\StateProviderInterface; |
| 8 | + |
| 9 | +final class MockStateProvider implements StateProviderInterface |
| 10 | +{ |
| 11 | + /** @var array|null $state */ |
| 12 | + protected static ?array $state; |
| 13 | + |
| 14 | + |
| 15 | + /** |
| 16 | + * Save the state. |
| 17 | + * |
| 18 | + * This function saves the state, and returns an id which can be used to |
| 19 | + * retrieve it later. |
| 20 | + * |
| 21 | + * @param array &$state The login request state. |
| 22 | + * @param string $stage The current stage in the login process. |
| 23 | + * @param bool $rawId Return a raw ID, without a restart URL. |
| 24 | + * |
| 25 | + * @return string Identifier which can be used to retrieve the state later. |
| 26 | + */ |
| 27 | + public static function saveState(array &$state, string $stage, bool $rawId = false): string |
| 28 | + { |
| 29 | + self::$state['PHPUnit'][$stage] = $state; |
| 30 | + return 'PHPUnit'; |
| 31 | + } |
| 32 | + |
| 33 | + |
| 34 | + /** |
| 35 | + * Retrieve saved state. |
| 36 | + * |
| 37 | + * This function retrieves saved state information. If the state information has been lost, |
| 38 | + * it will attempt to restart the request by calling the restart URL which is embedded in the |
| 39 | + * state information. If there is no restart information available, an exception will be thrown. |
| 40 | + * |
| 41 | + * @param string $id State identifier (with embedded restart information). |
| 42 | + * @param string $stage The stage the state should have been saved in. |
| 43 | + * @param bool $allowMissing Whether to allow the state to be missing. |
| 44 | + * |
| 45 | + * @return array|null State information, or NULL if the state is missing and $allowMissing is true. |
| 46 | + * @psalm-return ($allowMissing is true ? array|null : array) |
| 47 | + */ |
| 48 | + public static function loadState(string $id, string $stage, bool $allowMissing = false): ?array |
| 49 | + { |
| 50 | + return self::$state[$id][$stage]; |
| 51 | + } |
| 52 | +} |
0 commit comments