Add JSON and JSON/serialized types for Doctrine
[MAILPOET-2216]
This commit is contained in:
@@ -3,8 +3,11 @@
|
||||
namespace MailPoet\Doctrine;
|
||||
|
||||
use MailPoet\Config\Env;
|
||||
use MailPoet\Doctrine\Types\JsonOrSerializedType;
|
||||
use MailPoet\Doctrine\Types\JsonType;
|
||||
use MailPoetVendor\Doctrine\DBAL\DriverManager;
|
||||
use MailPoetVendor\Doctrine\DBAL\Platforms\MySqlPlatform;
|
||||
use MailPoetVendor\Doctrine\DBAL\Types\Type;
|
||||
use PDO;
|
||||
|
||||
class ConnectionFactory {
|
||||
@@ -13,6 +16,11 @@ class ConnectionFactory {
|
||||
|
||||
private $min_wait_timeout = 60;
|
||||
|
||||
private $types = [
|
||||
JsonType::NAME => JsonType::class,
|
||||
JsonOrSerializedType::NAME => JsonOrSerializedType::class,
|
||||
];
|
||||
|
||||
function createConnection() {
|
||||
$platform_class = self::PLATFORM_CLASS;
|
||||
$connection_params = [
|
||||
@@ -36,6 +44,7 @@ class ConnectionFactory {
|
||||
$connection_params['port'] = Env::$db_port;
|
||||
}
|
||||
|
||||
$this->setupTypes();
|
||||
return DriverManager::getConnection($connection_params);
|
||||
}
|
||||
|
||||
@@ -56,4 +65,14 @@ class ConnectionFactory {
|
||||
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET ' . implode(', ', $driver_options),
|
||||
];
|
||||
}
|
||||
|
||||
private function setupTypes() {
|
||||
foreach ($this->types as $name => $class) {
|
||||
if (Type::hasType($name)) {
|
||||
Type::overrideType($name, $class);
|
||||
} else {
|
||||
Type::addType($name, $class);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user