PHPackages                             thefredfox/cakephp-ip-type - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. thefredfox/cakephp-ip-type

ActiveCakephp-plugin[Database &amp; ORM](/categories/database)

thefredfox/cakephp-ip-type
==========================

IpType plugin for CakePHP

3.0(10y ago)8602↓100%MITPHPPHP &gt;=5.4.16

Since Dec 4Pushed 10y ago1 watchersCompare

[ Source](https://github.com/TheFRedFox/cakephp-ip-type)[ Packagist](https://packagist.org/packages/thefredfox/cakephp-ip-type)[ Docs](http://github.com/thefredfox/cakephp-ip-type)[ RSS](/packages/thefredfox-cakephp-ip-type/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

IpType plugin for CakePHP
=========================

[](#iptype-plugin-for-cakephp)

Description
-----------

[](#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](http://www.innogames.com). The permission was given to make this class public.

Installation
------------

[](#installation)

You can install this plugin into your CakePHP application using [composer](http://getcomposer.org).

The recommended way to install composer packages is:

```
composer require thefredfox/cakephp-ip-type
```

After that you have to load the plugin in your application's bootstrap file and map the type for the database as follows:

```
// in bootstrap file

Plugin::load('IpType');
Type::map('ip', 'IpType\Database\Type\IpType');
```

In the Table class itself you have to tell the column to be this type:

```
// in your Entity Table class (eg. UsersTable)

use Cake\Database\Schema\Table as Schema;

protected function _initializeSchema(Schema $schema) {
    $schema->columnType('ip', 'ip');
    return $schema;
}
```

Configuration
-------------

[](#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 `\UnexpectedValueException` will be thrown with the message: 'Could not decode the value, IpType::\_decode has to be a callable.' resp. '... encode ... IpType::\_encode ...'.

### Method Strings

[](#method-strings)

```
// in bootstrap file

/** @var IpType $ipType */
$ipType = Type::build('ip');
$ipType->_encode = 'ip2long'; // using global ip2long method for encoding (just IPv4 support)
$ipType->_decode = 'long2ip'; // using global long2ip method for decoding (just IPv4 support)
```

### Custom Functions

[](#custom-functions)

```
// in bootstrap file

/** @var IpType $ipType */
$ipType = Type::build('ip');
$ipType->_encode = function ($value) {
    return $value . '1'; // just concatenate a '1' at the end, for what reason ever
};
$ipType->_decode = function ($value) {
    return $value;
};
```

### Static Functions of a Class

[](#static-functions-of-a-class)

```
class TestClass {
    public static function staticEncode($value) { /*...*/ }
    public static function staticDecode($value) { /*...*/ }
}

/** @var IpType $ipType */
$ipType = Type::build('ip');
$ipType->_encode = 'TestClass::staticEncode';
$ipType->_decode = 'TestClass::staticDecode';
```

### Non Static Functions of a Class via Wrapper Function

[](#non-static-functions-of-a-class-via-wrapper-function)

```
class TestClass {
    public function encode($value) { /*...*/ }
    public function decode($value) { /*...*/ }
}

/** @var IpType $ipType */
$ipType = Type::build('ip');
$ipType->_encode = function ($value) {
   $object = new TestClass();
   return $object->encode($value);
};
$ipType->_decode = function ($value) {
   $object = new TestClass();
   return $object->decode($value);
};
```

Database
--------

[](#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.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3808d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1f4df641a82999a24e2e43b99c6a00dc7d82fb4d4fb52a23e69169f68c6c5bf0?d=identicon)[TheFRedFox](/maintainers/TheFRedFox)

---

Top Contributors

[![TheFRedFox](https://avatars.githubusercontent.com/u/5676670?v=4)](https://github.com/TheFRedFox "TheFRedFox (15 commits)")

---

Tags

cakephpcakephp3databaseipiptypeplugintypedatabasecakephpIP

### Embed Badge

![Health badge](/badges/thefredfox-cakephp-ip-type/health.svg)

```
[![Health](https://phpackages.com/badges/thefredfox-cakephp-ip-type/health.svg)](https://phpackages.com/packages/thefredfox-cakephp-ip-type)
```

###  Alternatives

[itbdw/ip-database

IP数据库 IPV4 IPV6（解析为国家、省、市、县、运营商）

1.5k123.8k7](/packages/itbdw-ip-database)[dereuromark/cakephp-databaselog

A CakePHP plugin for storing and viewing application logs in the database

44165.0k2](/packages/dereuromark-cakephp-databaselog)[webparking/laravel-type-safe-collection

This package provides type-safe extension of the laravel collection, forcing a single type of object.

378.2k](/packages/webparking-laravel-type-safe-collection)[imsamurai/cakephp-serializable-behaviour

Behavior for saving and reading serialized data from/into database

147.7k3](/packages/imsamurai-cakephp-serializable-behaviour)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
