<?php
namespace App\Doctrine\DBAL\Types;
use App\Model\Query\ConditionQuery\ConditionConfig;
use App\Util\Json;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\JsonType;
class ConditionConfigType extends JsonType
{
/**
* {@inheritdoc}
*/
public function getName(): string
{
return 'condition_config';
}
/**
* {@inheritdoc}
*/
public function requiresSQLCommentHint(AbstractPlatform $platform): bool
{
return true;
}
/**
* {@inheritdoc}
*/
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
if (is_null($value)) {
return null;
}
if ( ! $value instanceof ConditionConfig) {
throw new \LogicException('Invalid ConditionConfig');
}
return Json::encode($value);
}
/**
* {@inheritdoc}
*/
public function convertToPHPValue($value, AbstractPlatform $platform)
{
if (is_null($value)) {
return null;
}
return ConditionConfig::factory(
Json::decode($value, true),
);
}
}