sunchaser / doctrine-pgsql-ip
Doctrine type handlers for PostgreSQL's inet and cidr
Installs: 27 078
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: ^8.1
- doctrine/dbal: ^4.0
- rlanvin/php-ip: ^3.0
README
This library adds support for cidr
and inet
types of PostgreSQL in Doctrine using the rlanvin/php-ip library.
Installation
composer require sunchaser/doctrine-pgsql-ip
Usage
-
Register types in Doctrine
<?php use Doctrine\DBAL\Types\Type; use SunChaser\Doctrine\PgSql\InetType; use SunChaser\Doctrine\PgSql\CidrType; Type::addType(InetType::NAME, InetType::class); Type::addType(CidrType::NAME, CidrType::class);
-
Add type handling for schema operations
<?php use Doctrine\DBAL\Connection; use SunChaser\Doctrine\PgSql\InetType; use SunChaser\Doctrine\PgSql\CidrType; /** @var Connection $conn */ $conn->getDatabasePlatform()->registerDoctrineTypeMapping(InetType::PG_TYPE, InetType::NAME); $conn->getDatabasePlatform()->registerDoctrineTypeMapping(CidrType::PG_TYPE, CidrType::NAME);
inet
accepts and retrieves both \PhpIP\IP
for individual addresses
and \PhpIP\IPBlock
for network masks.
Please check the type when retrieving the data.
cidr
accepts and retrieves only \PhpIP\IPBlock
.
Upgrade
Changes in 3.0:
- Requirements were bumped to PHP 8.1 and Doctrine DBAL 4.0
Changes in 2.0:
leth/ip-address
was replaced withrlanvin/php-ip
- Requirements were bumped to PHP 8.0 and Doctrine DBAL 3.0