BigIntType.php
2 months ago
DateTimeTzToStringType.php
3 years ago
JsonOrSerializedType.php
2 months ago
JsonType.php
2 months ago
SerializedArrayType.php
2 months ago
index.php
3 years ago
SerializedArrayType.php
45 lines
| 1 | <?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing |
| 2 | |
| 3 | namespace MailPoet\Doctrine\Types; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoetVendor\Doctrine\DBAL\Platforms\AbstractPlatform; |
| 9 | use MailPoetVendor\Doctrine\DBAL\Types\Type; |
| 10 | |
| 11 | class SerializedArrayType extends Type { |
| 12 | const NAME = 'serialized_array'; |
| 13 | |
| 14 | public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { |
| 15 | return $platform->getClobTypeDeclarationSQL($fieldDeclaration); |
| 16 | } |
| 17 | |
| 18 | public function convertToDatabaseValue($value, AbstractPlatform $platform) { |
| 19 | return \serialize($value); |
| 20 | } |
| 21 | |
| 22 | public function convertToPHPValue($value, AbstractPlatform $platform) { |
| 23 | if ($value === null) { |
| 24 | return null; |
| 25 | } |
| 26 | $value = \is_resource($value) ? \stream_get_contents($value) : $value; |
| 27 | if (!\is_string($value)) { |
| 28 | return null; |
| 29 | } |
| 30 | $val = \unserialize($value); |
| 31 | if ($val === \false && $value !== 'b:0;') { |
| 32 | return null; |
| 33 | } |
| 34 | return $val; |
| 35 | } |
| 36 | |
| 37 | public function getName() { |
| 38 | return self::NAME; |
| 39 | } |
| 40 | |
| 41 | public function requiresSQLCommentHint(AbstractPlatform $platform) { |
| 42 | return true; |
| 43 | } |
| 44 | } |
| 45 |