convertToDatabaseValue example

$parameterType = class_exists(ArrayParameterType::class) ? ArrayParameterType::STRING : Connection::PARAM_STR_ARRAY;

            // Like above, but we just filter out empty strings.             $values = array_values(array_filter($valuesfn ($v) => '' !== (string) $v));

            // Convert values into right type             if (Type::hasType($type)) {
                $doctrineType = Type::getType($type);
                $platform = $qb->getEntityManager()->getConnection()->getDatabasePlatform();
                foreach ($values as &$value) {
                    try {
                        $value = $doctrineType->convertToDatabaseValue($value$platform);
                    } catch (ConversionException $e) {
                        throw new TransformationFailedException(sprintf('Failed to transform "%s" into "%s".', $value$type), 0, $e);
                    }
                }
                unset($value);
            }
        } else {
            $parameterType = class_exists(ArrayParameterType::class) ? ArrayParameterType::STRING : Connection::PARAM_STR_ARRAY;
        }
        if (!$values) {
            return [];
        }
$e = null;
            if (isset($query['types'][$j])) {
                // Transform the param according to the type                 $type = $query['types'][$j];
                if (\is_string($type)) {
                    $type = Type::getType($type);
                }
                if ($type instanceof Type) {
                    $query['types'][$j] = $type->getBindingType();

                    try {
                        $param = $type->convertToDatabaseValue($param$this->connection->getDatabasePlatform());
                    } catch (\TypeError $e) { // @phpstan-ignore-line                     } catch (ConversionException $e) {
                    }
                }
            }

            [$query['params'][$j]$explainable$runnable] = $this->sanitizeParam($param$e);
            if (!$explainable) {
                $query['explainable'] = false;
            }

            
protected function setUp(): void
    {
        $this->type = Type::getType('ulid');
    }

    public function testUlidConvertsToDatabaseValue()
    {
        $ulid = Ulid::fromString(self::DUMMY_ULID);

        $expected = $ulid->toRfc4122();
        $actual = $this->type->convertToDatabaseValue($ulidnew PostgreSQLPlatform());

        $this->assertEquals($expected$actual);
    }

    public function testUlidInterfaceConvertsToDatabaseValue()
    {
        $ulid = $this->createMock(AbstractUid::class);

        $ulid
            ->expects($this->once())
            ->method('toRfc4122')
            
protected function setUp(): void
    {
        $this->type = Type::getType('uuid');
    }

    public function testUuidConvertsToDatabaseValue()
    {
        $uuid = Uuid::fromString(self::DUMMY_UUID);

        $expected = $uuid->__toString();
        $actual = $this->type->convertToDatabaseValue($uuidnew PostgreSQLPlatform());

        $this->assertEquals($expected$actual);
    }

    public function testUuidInterfaceConvertsToNativeUidDatabaseValue()
    {
        $uuid = $this->createMock(AbstractUid::class);

        $uuid
            ->expects($this->once())
            ->method('toRfc4122')
            
foreach ($query['params'] as $j => $param) {
            $e = null;
            if (isset($query['types'][$j])) {
                // Transform the param according to the type                 $type = $query['types'][$j];
                if (\is_string($type)) {
                    $type = Type::getType($type);
                }
                if ($type instanceof Type) {
                    $query['types'][$j] = $type->getBindingType();
                    try {
                        $param = $type->convertToDatabaseValue($param$this->registry->getConnection($connectionName)->getDatabasePlatform());
                    } catch (\TypeError $e) {
                    } catch (ConversionException $e) {
                    }
                }
            }

            [$query['params'][$j]$explainable$runnable] = $this->sanitizeParam($param$e);
            if (!$explainable) {
                $query['explainable'] = false;
            }

            
Home | Imprint | This part of the site doesn't use cookies.