PHPackages                             erwane/cakephp-contact - 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. erwane/cakephp-contact

ActiveCakephp-plugin

erwane/cakephp-contact
======================

Cakephp plugin for manipulating Contact information (address, phone, ...)

3.0.1(1y ago)0992MITPHPPHP ^8.1

Since Apr 9Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Erwane/cakephp-contact)[ Packagist](https://packagist.org/packages/erwane/cakephp-contact)[ RSS](/packages/erwane-cakephp-contact/feed)WikiDiscussions 3.x Synced 2mo ago

READMEChangelogDependencies (6)Versions (13)Used By (0)

CakePHP 5.x plugin to manipulate contact data
=============================================

[](#cakephp-5x-plugin-to-manipulate-contact-data)

[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![codecov](https://camo.githubusercontent.com/bfa11497ed56fe1dc3a7d841d871b125df573fbca0aa9891f8c5ed690a73ceae/68747470733a2f2f636f6465636f762e696f2f6769746875622f457277616e652f63616b657068702d636f6e746163742f67726170682f62616467652e7376673f746f6b656e3d6344527a7a50716f7041)](https://codecov.io/github/Erwane/cakephp-contact)[![Packagist Downloads](https://camo.githubusercontent.com/137860bbb2eca8fb24ade1599c7addb9e3cd4bff39417a71773043c6a9ac2cf9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f457277616e652f63616b657068702d636f6e74616374)](https://packagist.org/packages/Erwane/cakephp-contact)[![Packagist Version](https://camo.githubusercontent.com/1ae7e2f0cb69f84be907b3c0849a3f7c6d9c05f2e982438ba2129b9e5e512ad7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f457277616e652f63616b657068702d636f6e74616374)](https://packagist.org/packages/Erwane/cakephp-contact)

CakePHP-Contact is here to help you save, test and display all locality and contact datas like phone &amp; address.

Version map
-----------

[](#version-map)

Contact pluginbranchCakePHP corePHP min1.x1.x^3.2PHP 7.22.x2.x^4.0PHP 7.23.x3.x^5.0PHP 8.1Documentation
-------------

[](#documentation)

- [Installation](#installing-with-composer)
- [Phone numbers](#phone-numbers)
    - [Utility](#utility)
    - [PhoneNumberType](#phonenumbertype)
    - [Validation](#phone-number-validation)
    - [Helper](#phone-helper)
- [Address](#address-trait)
    - [Configuration](#address-trait-configuration)

Installing with Composer
------------------------

[](#installing-with-composer)

Use composer to install it

```
composer require erwane/cakephp-contact
```

Phone numbers
-------------

[](#phone-numbers)

### Utility

[](#utility)

**Contact\\Utility\\Phone::format**(?string $text = null, array $options = \[\])

`$text` is string or null `$options` is an array with this possible options and output

- `country` : a country code like `FR` or `UK`
- `format` : \* `international`: +33 1 23 45 67 89 \* `national`: 01 23 45 67 89 \* `uri`: tel:+33-1-23-45-67-89 \* `short`: +33123456789

### PhoneNumberType

[](#phonenumbertype)

The phone number database type automatically format request data to an E164 phone number (+33....) It also format phone number from unformated database result.

#### How to use PhoneNumberType

[](#how-to-use-phonenumbertype)

```
// in src/Application.php
use Cake\Core\Exception\MissingPluginException;

public function bootstrap(): void
{
    // Load Contact plugin
    try {
        $this->addPlugin(\Contact\Plugin::class);
    } catch (MissingPluginException $e) {
        debug($e->getMessage());
    }
}

// in table file
use Cake\Database\Schema\TableSchemaInterface;
use Cake\Orm\Table;

class UsersTable extends Table
    /**
     * {@inheritDoc}
     */
    protected function _initializeSchema(TableSchemaInterface $schema): TableSchemaInterface
    {
        $schema->setColumnType('phone_number', 'phonenumber')
            ->setColumnType('mobile_number', 'phonenumber');

        return $schema;
    }
```

#### Default country

[](#default-country)

Phone number in forms are set in the user country format, like `0123456789` for France. But there can be conflict, depends of the user Country who fill the form. You can set `defaultCountry` for all phone number not set in international format.

```
// in config/bootstrap.php
// or after loaded user preference or website country
use Cake\Database\TypeFactory;
use Contact\Database\Type\PhoneNumberType;

$phoneNumberType = new PhoneNumberType();
$phoneNumberType->setDefaultCountry('BE');
TypeFactory::set('phonenumber', $phoneNumberType);
```

Now, all non international form phone numbers was formated with +32 prefix

### Phone number validation

[](#phone-number-validation)

Contact plugin provide a simple phone number validation rule

```
// in validation method

public function validationDefault(Validator $validator)
{
    $validator->setProvider('contact', 'Contact\Validation\ContactValidation');
    $validator->add('phone_number', [
        'number' => [
            'provider' => 'contact',
            'rule' => ['phone'],
        ],
    ]);
}

// You can pass country argument
$validator->add('phone_number', [
    'number' => [
        'provider' => 'contact',
        'rule' => ['phone', 'ES'],
    ],
]);
```

### Phone Helper

[](#phone-helper)

You can format a phone number in a really simple manner;

```
// In src/AppView.php
public function initialize(): void
{
    $this->loadHelper('Contact.Contact');
}

// in template file
echo $this->Contact->phone($entity->phone_number);

// Can pass options (see Utility/Phone::format() help)
echo $this->Contact->phone($entity->phone_number, [
    'country' => 'BE',
    'format' => 'uri',
]);
```

Address trait
-------------

[](#address-trait)

This trait must be attached to `\Cake\ORM\Entity` in your App. It take address data from Entity fields and format it to standard array or string format.

The fields and format can be configured in Entity or by method.

### Default

[](#default)

#### Address fields matching

[](#address-fields-matching)

By default, address will be extracted from this fields :

```
// ['key' => 'field name in database']
[
    'organization' => 'organization',
    'street1' => 'street1',
    'street2' => 'street2',
    'postalCode' => 'postalCode',
    'locality' => 'locality',
    'region' => 'Regions.title', // Pluralized table name
    'country' => 'Countries.title', // Pluralized table name
   ]

```

Data can be in an associated model. Use dot format `Countries.title` to set it.

#### Address text format

[](#address-text-format)

Address text (`$entity->address_text`) use `Cake\Utility\Text::insert()` method to format fields.

Default address text format is :

```
":organization
:street1
:street2
:postalCode :locality
:country"

```

### Address trait configuration

[](#address-trait-configuration)

You can change default configuration in two ways.

#### With methods

[](#with-methods)

```
// setAddressFields(array $fields, bool $merge = true)
$entity->setAddressFields(['organization' => 'name']);

// setAddressFormat(string $format)
$entity->setAddressFormat(":organization\n:country");
```

#### In entity

[](#in-entity)

```
use Cake\ORM\Entity;
use Contact\Model\Entity\AddressTrait;

class Company extends Entity
{
    use AddressTrait;

    protected $_addressFields = [
        'organization' => 'name',
        'street1' => 'address1',
        'street2' => 'address2',
        'postalCode' => 'postal_code',
        'locality' => 'city',
        'region' => 'Regions.name',
        'country' => 'Countries.name',
    ];

    protected $_addressFormat = ":street1 :street2\n:locality :postalCode\n:region :country";
}
```

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance41

Moderate activity, may be stable

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity79

Established project with proven stability

 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

Every ~246 days

Recently: every ~305 days

Total

11

Last Release

496d ago

Major Versions

1.x-dev → 2.0.02020-04-01

2.x-dev → 3.0.02025-01-03

PHP version history (2 changes)2.0.2PHP &gt;=7.2.0

3.0.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/91732d78336582954080932d4350d08420a053dbba6728f1727b5500ab931c65?d=identicon)[Erwane](/maintainers/Erwane)

---

Top Contributors

[![Erwane](https://avatars.githubusercontent.com/u/712604?v=4)](https://github.com/Erwane "Erwane (60 commits)")

---

Tags

cakephpcakephp-pluginaddresscakephpphonecontact

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/erwane-cakephp-contact/health.svg)

```
[![Health](https://phpackages.com/badges/erwane-cakephp-contact/health.svg)](https://phpackages.com/packages/erwane-cakephp-contact)
```

###  Alternatives

[cakephp/bake

Bake plugin for CakePHP

11211.2M158](/packages/cakephp-bake)[dereuromark/cakephp-tools

A CakePHP plugin containing lots of useful and reusable tools

338920.1k32](/packages/dereuromark-cakephp-tools)[dereuromark/cakephp-queue

The Queue plugin for CakePHP provides deferred task execution.

308850.3k14](/packages/dereuromark-cakephp-queue)[dereuromark/cakephp-ide-helper

CakePHP IdeHelper Plugin to improve auto-completion

1862.1M27](/packages/dereuromark-cakephp-ide-helper)[dereuromark/cakephp-tinyauth

A CakePHP plugin to handle user authentication and authorization the easy way.

129228.6k10](/packages/dereuromark-cakephp-tinyauth)[cakephp/queue

Queue plugin for CakePHP

36257.9k12](/packages/cakephp-queue)

PHPackages © 2026

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