1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Licensed to CRATE Technology GmbH("Crate") under one or more contributor |
4
|
|
|
* license agreements. See the NOTICE file distributed with this work for |
5
|
|
|
* additional information regarding copyright ownership. Crate licenses |
6
|
|
|
* this file to you under the Apache License, Version 2.0 (the "License"); |
7
|
|
|
* you may not use this file except in compliance with the License. You may |
8
|
|
|
* 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, WITHOUT |
14
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
15
|
|
|
* License for the specific language governing permissions and limitations |
16
|
|
|
* under the License. |
17
|
|
|
* |
18
|
|
|
* However, if you have executed another commercial license agreement |
19
|
|
|
* with Crate these terms will supersede the license and you may use the |
20
|
|
|
* software solely pursuant to the terms of the relevant commercial agreement. |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
namespace Crate\DBAL\Types; |
24
|
|
|
|
25
|
|
|
use Crate\PDO\PDO; |
26
|
|
|
use Doctrine\DBAL\Types\Type; |
27
|
|
|
use Doctrine\DBAL\Platforms\AbstractPlatform; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Type that maps a PHP sequential array to an array SQL type. |
31
|
|
|
* |
32
|
|
|
*/ |
33
|
|
|
class ArrayType extends Type |
34
|
|
|
{ |
35
|
|
|
|
36
|
|
|
const NAME = 'array'; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Gets the name of this type. |
40
|
|
|
* |
41
|
|
|
* @return string |
42
|
|
|
*/ |
43
|
74 |
|
public function getName() |
44
|
|
|
{ |
45
|
74 |
|
return self::NAME; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Gets the (preferred) binding type for values of this type that |
50
|
|
|
* can be used when binding parameters to prepared statements. |
51
|
|
|
* |
52
|
|
|
* @return integer |
53
|
|
|
*/ |
54
|
50 |
|
public function getBindingType() |
55
|
|
|
{ |
56
|
50 |
|
return PDO::PARAM_ARRAY; |
57
|
|
|
} |
58
|
|
|
|
59
|
56 |
|
public function convertToDatabaseValue($value, AbstractPlatform $platform) |
60
|
|
|
{ |
61
|
56 |
|
if (!is_array($value) || (count($value) > 0 && !(array_keys($value) === range(0, count($value) - 1)))) { |
62
|
4 |
|
return null; |
63
|
|
|
} |
64
|
52 |
|
return $value; |
65
|
|
|
} |
66
|
|
|
|
67
|
2 |
|
public function convertToPHPValue($value, AbstractPlatform $platform) |
68
|
|
|
{ |
69
|
2 |
|
return $value; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Gets the SQL declaration snippet for a field of this type. |
74
|
|
|
* |
75
|
|
|
* @param array $fieldDeclaration The field declaration. |
76
|
|
|
* @param AbstractPlatform $platform The currently used database platform. |
77
|
|
|
* @return string |
78
|
|
|
* @throws \Doctrine\DBAL\DBALException |
79
|
|
|
*/ |
80
|
8 |
|
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) |
81
|
|
|
{ |
82
|
8 |
|
$options = !array_key_exists('platformOptions', $fieldDeclaration) ? |
83
|
8 |
|
array() : $fieldDeclaration['platformOptions']; |
84
|
8 |
|
return $this->getArrayTypeDeclarationSQL($platform, $fieldDeclaration, $options); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Gets the SQL snippet used to declare an ARRAY column type. |
89
|
|
|
* |
90
|
|
|
* @param AbstractPlatform $platform |
91
|
|
|
* @param array $field |
92
|
|
|
* |
93
|
|
|
* @param array $options |
94
|
|
|
* @return string |
95
|
|
|
* @throws \Doctrine\DBAL\DBALException |
96
|
|
|
*/ |
97
|
8 |
|
public function getArrayTypeDeclarationSQL(AbstractPlatform $platform, array $field, array $options) |
98
|
|
|
{ |
99
|
8 |
|
$type = array_key_exists('type', $options) ? $options['type'] : Type::STRING; |
|
|
|
|
100
|
8 |
|
return 'ARRAY ( ' . Type::getType($type)->getSQLDeclaration($field, $platform) . ' )'; |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
This class constant has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.