hasNativeGuidType($platform)) { return $platform->getGuidTypeDeclarationSQL($column); } return $platform->getBinaryTypeDeclarationSQL([ 'length' => 16, 'fixed' => true, ]); } #[Override] public function convertToPHPValue( mixed $value, AbstractPlatform $platform, ): Ulid|null { if ($value instanceof Ulid || $value === null) { return $value; } if (! is_string($value)) { throw InvalidType::new($value, self::NAME, ['null', 'string', self::class]); } try { return Ulid::fromString($value); } catch (InvalidArgumentException $e) { throw ValueNotConvertible::new($value, self::NAME, null, $e); } } #[Override] public function convertToDatabaseValue( mixed $value, AbstractPlatform $platform, ): string|null { $toStringFunc = static fn(Ulid $v): string => $v->toRfc4122(); if (! $this->hasNativeGuidType($platform)) { $toStringFunc = static fn(Ulid $v): string => $v->toBinary(); } if ($value instanceof Ulid) { return $toStringFunc($value); } if ($value === null || $value === '') { return null; } if (! is_string($value)) { throw InvalidType::new($value, self::NAME, ['null', 'string', self::class]); } try { return $toStringFunc(Ulid::fromString($value)); } catch (InvalidArgumentException $e) { throw ValueNotConvertible::new($value, self::NAME, null, $e); } } private function hasNativeGuidType(AbstractPlatform $platform): bool { return $platform->getGuidTypeDeclarationSQL([]) !== $platform->getStringTypeDeclarationSQL([ 'fixed' => true, 'length' => 36, ]); } public static function register(): void { if (Type::hasType(self::NAME)) { Type::overrideType(self::NAME, self::class); return; } Type::addType(self::NAME, self::class); } }