vendor/sonata-project/doctrine-extensions/src/Types/JsonType.php line 22

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of the Sonata Project package.
  5.  *
  6.  * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  7.  *
  8.  * For the full copyright and license information, please view the LICENSE
  9.  * file that was distributed with this source code.
  10.  */
  11. namespace Sonata\Doctrine\Types;
  12. use Doctrine\DBAL\Platforms\AbstractPlatform;
  13. use Doctrine\DBAL\Types\Type;
  14. @trigger_error(
  15.     'The '.__NAMESPACE__.'\JsonType class is deprecated since 1.2 in favor of '.
  16.     'Doctrine\DBAL\Types\JsonType, and will be removed in 2.0.',
  17.     E_USER_DEPRECATED
  18. );
  19. /**
  20.  * Convert a value into a json string to be stored into the persistency layer.
  21.  */
  22. class JsonType extends Type
  23. {
  24.     public const JSON 'json';
  25.     public function convertToPHPValue($valueAbstractPlatform $platform)
  26.     {
  27.         return json_decode((string) $valuetrue);
  28.     }
  29.     public function convertToDatabaseValue($valueAbstractPlatform $platform)
  30.     {
  31.         return json_encode($value);
  32.     }
  33.     public function getName()
  34.     {
  35.         return self::JSON;
  36.     }
  37.     public function getSQLDeclaration(array $fieldDeclarationAbstractPlatform $platform)
  38.     {
  39.         return $platform->getClobTypeDeclarationSQL($fieldDeclaration);
  40.     }
  41.     public function requiresSQLCommentHint(AbstractPlatform $platform)
  42.     {
  43.         return true;
  44.     }
  45. }