|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright 2022 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 Surfnet\StepupMiddleware\ApiBundle\Doctrine\Type; |
|
20
|
|
|
|
|
21
|
|
|
use Doctrine\DBAL\Platforms\AbstractPlatform; |
|
22
|
|
|
use Doctrine\DBAL\Types\ConversionException; |
|
23
|
|
|
use Doctrine\DBAL\Types\IntegerType; |
|
24
|
|
|
use Surfnet\Stepup\Configuration\Value\SsoRegistrationBypassOption; |
|
|
|
|
|
|
25
|
|
|
use TypeError; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Custom Type for the SsoRegistrationBypassOption Value Object |
|
29
|
|
|
*/ |
|
|
|
|
|
|
30
|
|
|
class SsoRegistrationBypassOptionType extends IntegerType |
|
31
|
|
|
{ |
|
32
|
|
|
public const NAME = 'stepup_sso_registration_bypass_option'; |
|
33
|
|
|
|
|
34
|
|
|
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string |
|
35
|
|
|
{ |
|
36
|
|
|
return $platform->getIntegerTypeDeclarationSQL($column); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): ?int |
|
40
|
|
|
{ |
|
41
|
|
|
if (is_null($value)) { |
|
42
|
|
|
return null; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
if (!$value instanceof SsoRegistrationBypassOption) { |
|
46
|
|
|
throw new ConversionException( |
|
47
|
|
|
sprintf( |
|
48
|
|
|
"Encountered illegal sso registration bypass option %s '%s', expected a |
|
49
|
|
|
SsoRegistrationBypassOption instance", |
|
50
|
|
|
get_debug_type($value), |
|
51
|
|
|
is_scalar($value) ? (string)$value : '', |
|
52
|
|
|
), |
|
53
|
|
|
); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
return (int)$value->isEnabled(); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function convertToPHPValue($value, AbstractPlatform $platform): ?SsoRegistrationBypassOption |
|
60
|
|
|
{ |
|
61
|
|
|
if (is_null($value)) { |
|
62
|
|
|
return null; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
try { |
|
66
|
|
|
$ssoRegistrationBypassOption = new SsoRegistrationBypassOption((bool)$value); |
|
67
|
|
|
} catch (TypeError $e) { |
|
68
|
|
|
// get nice standard message, so we can throw it keeping the exception chain |
|
69
|
|
|
$doctrineExceptionMessage = ConversionException::conversionFailed( |
|
70
|
|
|
$value, |
|
71
|
|
|
$this->getName(), |
|
72
|
|
|
)->getMessage(); |
|
73
|
|
|
|
|
74
|
|
|
throw new ConversionException($doctrineExceptionMessage, 0, $e); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
return $ssoRegistrationBypassOption; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function getName(): string |
|
81
|
|
|
{ |
|
82
|
|
|
return self::NAME; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|