Introduce serialized_array type
[MAILPOET-2710]
This commit is contained in:
committed by
Jack Kitterhing
parent
ede14fc661
commit
7568d57757
@ -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() {
|
||||
|
38
lib/Doctrine/Types/SerializedArrayType.php
Normal file
38
lib/Doctrine/Types/SerializedArrayType.php
Normal 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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user