Introduce serialized_array type

[MAILPOET-2710]
This commit is contained in:
Rostislav Wolny
2020-02-13 20:57:50 +01:00
committed by Jack Kitterhing
parent ede14fc661
commit 7568d57757
2 changed files with 40 additions and 0 deletions

View File

@ -5,6 +5,7 @@ namespace MailPoet\Doctrine;
use MailPoet\Config\Env;
use MailPoet\Doctrine\Types\JsonOrSerializedType;
use MailPoet\Doctrine\Types\JsonType;
use MailPoet\Doctrine\Types\SerializedArrayType;
use MailPoetVendor\Doctrine\DBAL\DriverManager;
use MailPoetVendor\Doctrine\DBAL\Platforms\MySqlPlatform;
use MailPoetVendor\Doctrine\DBAL\Types\Type;
@ -19,6 +20,7 @@ class ConnectionFactory {
private $types = [
JsonType::NAME => JsonType::class,
JsonOrSerializedType::NAME => JsonOrSerializedType::class,
SerializedArrayType::NAME => SerializedArrayType::class,
];
public function createConnection() {

View File

@ -0,0 +1,38 @@
<?php
namespace MailPoet\Doctrine\Types;
use MailPoetVendor\Doctrine\DBAL\Platforms\AbstractPlatform;
use MailPoetVendor\Doctrine\DBAL\Types\Type;
class SerializedArrayType extends Type {
const NAME = 'serialized_array';
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) {
return $platform->getClobTypeDeclarationSQL($fieldDeclaration);
}
public function convertToDatabaseValue($value, AbstractPlatform $platform) {
return \serialize($value);
}
public function convertToPHPValue($value, AbstractPlatform $platform) {
if ($value === null) {
return null;
}
$value = \is_resource($value) ? \stream_get_contents($value) : $value;
$val = \unserialize($value);
if ($val === \false && $value !== 'b:0;') {
return null;
}
return $val;
}
public function getName() {
return self::NAME;
}
public function requiresSQLCommentHint(AbstractPlatform $platform) {
return true;
}
}