Skip to content

Commit 167fb9e

Browse files
committed
Add ConsentVersion value object
This represents the consent type at hand (implicit or explicit consent). A third option is that no consent has been given.
1 parent 00a4623 commit 167fb9e

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2010 SURFnet B.V.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
namespace OpenConext\EngineBlock\Authentication\Value;
20+
21+
use OpenConext\EngineBlock\Assert\Assertion;
22+
23+
final class ConsentVersion
24+
{
25+
const STABLE = 'stable';
26+
const UNSTABLE = 'unstable';
27+
const NOT_GIVEN = 'not-given';
28+
29+
/**
30+
* @var string
31+
*/
32+
private $consentVersion;
33+
34+
public static function stable(): ConsentVersion
35+
{
36+
return new self(self::STABLE);
37+
}
38+
39+
public static function unstable(): ConsentVersion
40+
{
41+
return new self(self::UNSTABLE);
42+
}
43+
44+
public static function notGiven(): ConsentVersion
45+
{
46+
return new self(self::NOT_GIVEN);
47+
}
48+
49+
public function __construct(string $consentVersion)
50+
{
51+
Assertion::choice(
52+
$consentVersion,
53+
[self::UNSTABLE, self::STABLE, self::NOT_GIVEN],
54+
'ConsentVersion must be one of ConsentVersion::STABLE, ConsentVersion::NOT_GIVEN or ConsentVersion::UNSTABLE'
55+
);
56+
57+
$this->consentVersion = $consentVersion;
58+
}
59+
60+
public function given(): bool
61+
{
62+
return $this->consentVersion !== self::NOT_GIVEN;
63+
}
64+
65+
/**
66+
* @return string
67+
*/
68+
public function __toString()
69+
{
70+
return $this->consentVersion;
71+
}
72+
73+
public function isUnstable(): bool
74+
{
75+
return $this->consentVersion === self::UNSTABLE;
76+
}
77+
}

0 commit comments

Comments
 (0)