Skip to content

Instantly share code, notes, and snippets.

@capricornusx
Created April 14, 2025 09:42
Show Gist options
  • Save capricornusx/f99b4b41bfa4ee8f6e458fc7fc23fb67 to your computer and use it in GitHub Desktop.
Save capricornusx/f99b4b41bfa4ee8f6e458fc7fc23fb67 to your computer and use it in GitHub Desktop.
<?php
declare(strict_types=1);
namespace App\Infrastructure\Doctrine\Type;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
class InetType extends Type
{
public const TYPE_NAME = 'inet_type';
public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): ?string
{
if (!filter_var($value, FILTER_VALIDATE_IP)) {
return null;
}
return $value;
}
public function getName(): string
{
return self::TYPE_NAME;
}
public function requiresSQLCommentHint(AbstractPlatform $platform): bool
{
return true;
}
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
return 'inet';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment