Download the PHP package thefredfox/cakephp-ip-type without Composer
On this page you can find all versions of the php package thefredfox/cakephp-ip-type. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download thefredfox/cakephp-ip-type
More information about thefredfox/cakephp-ip-type
Files in thefredfox/cakephp-ip-type
Package cakephp-ip-type
Short Description IpType plugin for CakePHP
License MIT
Homepage http://github.com/thefredfox/cakephp-ip-type
Informations about the package cakephp-ip-type
IpType plugin for CakePHP
Description
An Ip Type for the Database Framework of CakePHP, which converts raw ip addresses represented as human readable strings (127.0.0.1, ::1) to byte strings with inet_pton to store them into a database.
The final converted value for the database is meant to be stored as a LOB value. I used a VARBINARY with 16 bytes. It is long enough for also IPv6 addresses.
The class was written for an application for InnoGames GmbH. The permission was given to make this class public.
Installation
You can install this plugin into your CakePHP application using composer.
The recommended way to install composer packages is:
After that you have to load the plugin in your application's bootstrap file and map the type for the database as follows:
In the Table class itself you have to tell the column to be this type:
Configuration
The default function for encoding and decoding is 'inet_pton' resp. 'inet_ntop'. However it is possible to set the encode (toDatabase) and decode (toPHP) methods as callables.
Is the variable not a callable an will be thrown with the message: 'Could not decode the value, IpType::_decode has to be a callable.' resp. '... encode ... IpType::_encode ...'.
Method Strings
Custom Functions
Static Functions of a Class
Non Static Functions of a Class via Wrapper Function
Database
The final converted value for the database is meant to be stored as a LOB value. I used a VARBINARY with 16 bytes. It is long enough for also IPv6 addresses.