1 | <?php |
||
2 | /* |
||
3 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||
4 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||
5 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||
6 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||
7 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||
8 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||
9 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||
10 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||
11 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
12 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||
13 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
14 | * |
||
15 | * This software consists of voluntary contributions made by many individuals |
||
16 | * and is licensed under the MIT license. For more information, see |
||
17 | * <http://www.doctrine-project.org>. |
||
18 | */ |
||
19 | |||
20 | namespace Doctrine\DBAL\Types; |
||
21 | |||
22 | use Doctrine\DBAL\Platforms\AbstractPlatform; |
||
23 | |||
24 | /** |
||
25 | * Array Type which can be used for simple values. |
||
26 | * |
||
27 | * Only use this type if you are sure that your values cannot contain a ",". |
||
28 | * |
||
29 | * @since 2.3 |
||
30 | * @author Johannes M. Schmitt <[email protected]> |
||
31 | */ |
||
32 | class SimpleArrayType extends Type |
||
33 | { |
||
34 | /** |
||
35 | * {@inheritdoc} |
||
36 | */ |
||
37 | public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) |
||
38 | { |
||
39 | return $platform->getClobTypeDeclarationSQL($fieldDeclaration); |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * {@inheritdoc} |
||
44 | */ |
||
45 | public function convertToDatabaseValue($value, AbstractPlatform $platform) |
||
46 | { |
||
47 | if (!$value) { |
||
48 | return null; |
||
49 | } |
||
50 | |||
51 | return implode(',', $value); |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * {@inheritdoc} |
||
56 | */ |
||
57 | View Code Duplication | public function convertToPHPValue($value, AbstractPlatform $platform) |
|
58 | { |
||
59 | if ($value === null) { |
||
60 | return []; |
||
61 | } |
||
62 | |||
63 | $value = (is_resource($value)) ? stream_get_contents($value) : $value; |
||
64 | |||
65 | return explode(',', $value); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
66 | } |
||
67 | |||
68 | /** |
||
69 | * {@inheritdoc} |
||
70 | */ |
||
71 | 17 | public function getName() |
|
72 | { |
||
73 | 17 | return Type::SIMPLE_ARRAY; |
|
74 | } |
||
75 | |||
76 | /** |
||
77 | * {@inheritdoc} |
||
78 | */ |
||
79 | 814 | public function requiresSQLCommentHint(AbstractPlatform $platform) |
|
80 | { |
||
81 | 814 | return true; |
|
82 | } |
||
83 | } |
||
84 |