@@ 24-92 (lines=69) @@ | ||
21 | use JsonSerializable; |
|
22 | use Surfnet\Stepup\Exception\InvalidArgumentException; |
|
23 | ||
24 | class SelectRaaOption implements JsonSerializable |
|
25 | { |
|
26 | /** |
|
27 | * @var InstitutionSet|null |
|
28 | */ |
|
29 | private $institutions; |
|
30 | ||
31 | /** |
|
32 | * SelectRaaOption constructor. |
|
33 | * @param string[]|null $selectRaaOption |
|
34 | */ |
|
35 | public function __construct($selectRaaOption) |
|
36 | { |
|
37 | if (!is_null($selectRaaOption) && !is_array($selectRaaOption)) { |
|
38 | throw InvalidArgumentException::invalidType( |
|
39 | 'null or string[]', |
|
40 | 'selectRaaOption', |
|
41 | $selectRaaOption |
|
42 | ); |
|
43 | } |
|
44 | ||
45 | // Sort the array values alphabetically |
|
46 | if (is_array($selectRaaOption)) { |
|
47 | sort($selectRaaOption); |
|
48 | $this->institutions = InstitutionSet::fromInstitutionConfig($selectRaaOption); |
|
49 | } |
|
50 | } |
|
51 | ||
52 | public static function getDefault() |
|
53 | { |
|
54 | return new self(null); |
|
55 | } |
|
56 | ||
57 | public function equals(SelectRaaOption $other) |
|
58 | { |
|
59 | $thisValue = null; |
|
60 | $otherValue = null; |
|
61 | if (!is_null($this->getInstitutions())) { |
|
62 | $thisValue = $this->getInstitutions()->toScalarArray(); |
|
63 | } |
|
64 | if (!is_null($other->getInstitutions())) { |
|
65 | $otherValue = $other->getInstitutions()->toScalarArray(); |
|
66 | } |
|
67 | return $thisValue === $otherValue; |
|
68 | } |
|
69 | ||
70 | public function isOption($option) |
|
71 | { |
|
72 | return is_array($this->institutions) && in_array($this->institutions, $option); |
|
73 | } |
|
74 | ||
75 | public function hasOptions() |
|
76 | { |
|
77 | return is_array($this->institutions); |
|
78 | } |
|
79 | ||
80 | public function getInstitutions() |
|
81 | { |
|
82 | return $this->institutions; |
|
83 | } |
|
84 | ||
85 | public function jsonSerialize() |
|
86 | { |
|
87 | if (is_null($this->getInstitutions())) { |
|
88 | return $this->getInstitutions(); |
|
89 | } |
|
90 | return $this->getInstitutions()->toScalarArray(); |
|
91 | } |
|
92 | } |
|
93 |
@@ 24-91 (lines=68) @@ | ||
21 | use JsonSerializable; |
|
22 | use Surfnet\Stepup\Exception\InvalidArgumentException; |
|
23 | ||
24 | class UseRaaOption implements JsonSerializable |
|
25 | { |
|
26 | /** |
|
27 | * @var InstitutionSet|null |
|
28 | */ |
|
29 | private $institutions; |
|
30 | ||
31 | /** |
|
32 | * UseRaaOption constructor. |
|
33 | * @param string[]|null $useRaaOption |
|
34 | */ |
|
35 | public function __construct($useRaaOption) |
|
36 | { |
|
37 | if (!is_null($useRaaOption) && !is_array($useRaaOption)) { |
|
38 | throw InvalidArgumentException::invalidType( |
|
39 | 'null or string[]', |
|
40 | 'useRaaOption', |
|
41 | $useRaaOption |
|
42 | ); |
|
43 | } |
|
44 | ||
45 | // Sort the array values alphabetically |
|
46 | if (is_array($useRaaOption)) { |
|
47 | sort($useRaaOption); |
|
48 | $this->institutions = InstitutionSet::fromInstitutionConfig($useRaaOption); |
|
49 | } |
|
50 | } |
|
51 | ||
52 | public static function getDefault() |
|
53 | { |
|
54 | return new self(null); |
|
55 | } |
|
56 | ||
57 | public function equals(UseRaaOption $other) |
|
58 | { |
|
59 | $thisValue = null; |
|
60 | $otherValue = null; |
|
61 | if (!is_null($this->getInstitutions())) { |
|
62 | $thisValue = $this->getInstitutions()->toScalarArray(); |
|
63 | } |
|
64 | if (!is_null($other->getInstitutions())) { |
|
65 | $otherValue = $other->getInstitutions()->toScalarArray(); |
|
66 | } |
|
67 | return $thisValue === $otherValue; |
|
68 | } |
|
69 | ||
70 | public function isOption($option) |
|
71 | { |
|
72 | return is_array($this->institutions) && in_array($this->institutions, $option); |
|
73 | } |
|
74 | ||
75 | public function hasOptions() |
|
76 | { |
|
77 | return is_array($this->institutions); |
|
78 | } |
|
79 | ||
80 | public function getInstitutions() |
|
81 | { |
|
82 | return $this->institutions; |
|
83 | } |
|
84 | public function jsonSerialize() |
|
85 | { |
|
86 | if (is_null($this->getInstitutions())) { |
|
87 | return $this->getInstitutions(); |
|
88 | } |
|
89 | return $this->getInstitutions()->toScalarArray(); |
|
90 | } |
|
91 | } |
|
92 |
@@ 24-92 (lines=69) @@ | ||
21 | use JsonSerializable; |
|
22 | use Surfnet\Stepup\Exception\InvalidArgumentException; |
|
23 | ||
24 | class UseRaOption implements JsonSerializable |
|
25 | { |
|
26 | /** |
|
27 | * @var InstitutionSet|null |
|
28 | */ |
|
29 | private $institutions; |
|
30 | ||
31 | /** |
|
32 | * UseRaOption constructor. |
|
33 | * @param null|array $useRaOption |
|
34 | */ |
|
35 | public function __construct($useRaOption) |
|
36 | { |
|
37 | if (!is_null($useRaOption) && !is_array($useRaOption)) { |
|
38 | throw InvalidArgumentException::invalidType( |
|
39 | 'null or string[]', |
|
40 | 'useRaOption', |
|
41 | $useRaOption |
|
42 | ); |
|
43 | ||
44 | } |
|
45 | // Sort the array values alphabetically |
|
46 | if (is_array($useRaOption)) { |
|
47 | sort($useRaOption); |
|
48 | $this->institutions = InstitutionSet::fromInstitutionConfig($useRaOption); |
|
49 | } |
|
50 | } |
|
51 | ||
52 | public static function getDefault() |
|
53 | { |
|
54 | return new self(null); |
|
55 | } |
|
56 | ||
57 | public function equals(UseRaOption $other) |
|
58 | { |
|
59 | $thisValue = null; |
|
60 | $otherValue = null; |
|
61 | if (!is_null($this->getInstitutions())) { |
|
62 | $thisValue = $this->getInstitutions()->toScalarArray(); |
|
63 | } |
|
64 | if (!is_null($other->getInstitutions())) { |
|
65 | $otherValue = $other->getInstitutions()->toScalarArray(); |
|
66 | } |
|
67 | return $thisValue === $otherValue; |
|
68 | } |
|
69 | ||
70 | public function isOption($option) |
|
71 | { |
|
72 | return is_array($this->institutions) && in_array($this->institutions, $option); |
|
73 | } |
|
74 | ||
75 | public function hasOptions() |
|
76 | { |
|
77 | return is_array($this->institutions); |
|
78 | } |
|
79 | ||
80 | public function getInstitutions() |
|
81 | { |
|
82 | return $this->institutions; |
|
83 | } |
|
84 | ||
85 | public function jsonSerialize() |
|
86 | { |
|
87 | if (is_null($this->getInstitutions())) { |
|
88 | return $this->getInstitutions(); |
|
89 | } |
|
90 | return $this->getInstitutions()->toScalarArray(); |
|
91 | } |
|
92 | } |
|
93 |