src/App/Doctrine/DBAL/Types/ConditionConfigType.php line 47

Open in your IDE?
  1. <?php
  2. namespace App\Doctrine\DBAL\Types;
  3. use App\Model\Query\ConditionQuery\ConditionConfig;
  4. use App\Util\Json;
  5. use Doctrine\DBAL\Platforms\AbstractPlatform;
  6. use Doctrine\DBAL\Types\JsonType;
  7. class ConditionConfigType extends JsonType
  8. {
  9.     /**
  10.      * {@inheritdoc}
  11.      */
  12.     public function getName(): string
  13.     {
  14.         return 'condition_config';
  15.     }
  16.     /**
  17.      * {@inheritdoc}
  18.      */
  19.     public function requiresSQLCommentHint(AbstractPlatform $platform): bool
  20.     {
  21.         return true;
  22.     }
  23.     /**
  24.      * {@inheritdoc}
  25.      */
  26.     public function convertToDatabaseValue($valueAbstractPlatform $platform)
  27.     {
  28.         if (is_null($value)) {
  29.             return null;
  30.         }
  31.         if ( ! $value instanceof ConditionConfig) {
  32.             throw new \LogicException('Invalid ConditionConfig');
  33.         }
  34.         return Json::encode($value);
  35.     }
  36.     /**
  37.      * {@inheritdoc}
  38.      */
  39.     public function convertToPHPValue($valueAbstractPlatform $platform)
  40.     {
  41.         if (is_null($value)) {
  42.             return null;
  43.         }
  44.         return ConditionConfig::factory(
  45.             Json::decode($valuetrue),
  46.         );
  47.     }
  48. }