1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2014 SURFnet bv |
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\Type; |
24
|
|
|
use Surfnet\Stepup\Identity\Value\DocumentNumber; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Custom Type for the Surfnet\Stepup\Identity\Value\DocumentNumber Object |
28
|
|
|
*/ |
29
|
|
|
class DocumentNumberType extends Type |
30
|
|
|
{ |
31
|
|
|
const NAME = 'stepup_document_number'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param array $fieldDeclaration |
35
|
|
|
* @param AbstractPlatform $platform |
36
|
|
|
* @return string |
37
|
|
|
* @throws \Doctrine\DBAL\DBALException |
38
|
|
|
*/ |
39
|
|
|
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) |
40
|
|
|
{ |
41
|
|
|
return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param mixed $value |
46
|
|
|
* @param AbstractPlatform $platform |
47
|
|
|
* @return null|string |
48
|
|
|
*/ |
49
|
|
|
public function convertToDatabaseValue($value, AbstractPlatform $platform) |
50
|
|
|
{ |
51
|
|
|
if (!$value instanceof DocumentNumber) { |
52
|
|
|
return null; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
return (string) $value; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param mixed $value |
60
|
|
|
* @param AbstractPlatform $platform |
61
|
|
|
* @return null|DocumentNumber |
62
|
|
|
* @throws ConversionException |
63
|
|
|
*/ |
64
|
|
|
public function convertToPHPValue($value, AbstractPlatform $platform) |
65
|
|
|
{ |
66
|
|
|
if (is_null($value)) { |
67
|
|
|
return null; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return new DocumentNumber($value); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function getName() |
74
|
|
|
{ |
75
|
|
|
return self::NAME; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|