-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
SimpleArrayType.php
88 lines (76 loc) · 1.79 KB
/
SimpleArrayType.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
namespace Doctrine\DBAL\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\Deprecations\Deprecation;
use function count;
use function explode;
use function implode;
use function is_array;
use function is_resource;
use function stream_get_contents;
/**
* Array Type which can be used for simple values.
*
* Only use this type if you are sure that your values cannot contain a ",".
*/
class SimpleArrayType extends Type
{
/**
* {@inheritdoc}
*/
public function getSQLDeclaration(array $column, AbstractPlatform $platform)
{
return $platform->getClobTypeDeclarationSQL($column);
}
/**
* {@inheritdoc}
*
* @param mixed $value
*
* @return string|null
*/
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
if (! is_array($value) || count($value) === 0) {
return null;
}
return implode(',', $value);
}
/**
* {@inheritdoc}
*
* @param mixed $value
*
* @return list<string>
*/
public function convertToPHPValue($value, AbstractPlatform $platform)
{
if ($value === null) {
return [];
}
$value = is_resource($value) ? stream_get_contents($value) : $value;
return explode(',', $value);
}
/**
* {@inheritdoc}
*/
public function getName()
{
return Types::SIMPLE_ARRAY;
}
/**
* {@inheritdoc}
*
* @deprecated
*/
public function requiresSQLCommentHint(AbstractPlatform $platform)
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5509',
'%s is deprecated.',
__METHOD__,
);
return true;
}
}