PHP code example of arokettu / ip-address-doctrine

1. Go to this page and download the library: Download arokettu/ip-address-doctrine library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

arokettu / ip-address-doctrine example snippets




use Arokettu\IP\AnyIPAddress;
use Arokettu\IP\Doctrine\IPAddressType;
use Arokettu\IP\Doctrine\VendorSpecific\PostgreSQL\InetType;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Types\Type;
use Doctrine\ORM\Mapping\Column;

// first register types you need
Type::addType(IPAddressType::NAME, IPAddressType::class);

// native type should also be registered in the platform
Type::addType(InetType::NAME, InetType::class);

$db = DriverManager::getConnection(/* ... */); // when initializing DBAL
$db->getDatabasePlatform()->registerDoctrineTypeMapping(InetType::NATIVE_TYPE, InetType::NAME);

// apply to the object:

class Model
{
    #[Column(type: IPAddressType::NAME)]
    public AnyIPAddress $ip;

    #[Column(type: InetType::NAME)]
    public AnyIPAddress $native_ip;
}