PHPackages                             jmjjg/cakephp3-database - 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. jmjjg/cakephp3-database

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

jmjjg/cakephp3-database
=======================

CakePHP 3 plugin that provides classes for adding default validation rules from the database table schema and cleaning data being saved.

1.0.0-RC1(9y ago)1221[2 issues](https://github.com/jmjjg/cakephp3-database/issues)GPL-2.0+PHP

Since Jan 22Pushed 9y ago1 watchersCompare

[ Source](https://github.com/jmjjg/cakephp3-database)[ Packagist](https://packagist.org/packages/jmjjg/cakephp3-database)[ Docs](https://github.com/jmjjg/cakephp3-database)[ RSS](/packages/jmjjg-cakephp3-database/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

Database
========

[](#database)

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

[](#description)

CakePHP 3 plugin that provides classes for adding default validation rules from the database table schema and cleaning data being saved.

Caching is enabled by default but can be disabled in the configuration or at run-time.

Works well only with CakePHP 3.3.x (tested with CakePHP 3.3.12).

Main classes
------------

[](#main-classes)

AutovalidateBehavior reads various informations from the database table schema, such as column type, the fact that the column can be NULL, foreign key constraints, unique constraints and automatically adds those validation rules to the default ones.

FormattableBehavior cleans up data before validation or saving using configurable static class methods. The columns on which the formatters are applied can be defined based on column type and field name regular expression.

Setup
-----

[](#setup)

Assuming the plugin is installed under `plugins/Database`, add the following to `config/bootstrap.php`:

```
Plugin::load('Database', ['autoload' => true]);
```

### Settings

[](#settings)

The following global settings can optionally be added to the `config/app.php` file.

```
return [
    // ...
    'plugin' =>  [
        // Custom Database plugin behavior configuration
        'Database' => [
            'AutovalidateBehavior' => [
                'cache' => false
            ],
            'FormattableBehavior' => [
                'cache' => false
            ]
        ]
    ],
    // ...
];
```

Usage
-----

[](#usage)

The following code should be added to your table classes, inside the initialize() method.

The two behaviors are independant and can be loaded in any order.

Note that NULL and boolean TRUE and are equivalent as configuration values.

```
public function initialize(array $config)
{
    // ...
        $this->addBehavior('DatabaseAutovalidate',
            [
                'className' => 'Database.Autovalidate',
                // Default values
                // 1°) Accepted validator names, as a string or an array of strings, NULL for any
                'accepted' => null,
                // 2°) Cache validation rules and their error messages ? NULL for global settings
                'cache' => null,
                // 3°) Domain to use for error messages
                'domain' => 'database'
            ]
        );

        $this->addBehavior('DatabaseFormattable',
            [
                'className' => 'Database.Formattable',
                // Default values
                // 1°) Cache formatters and the field list they apply to ? NULL for global settings
                'cache' => null,
                // 2°) List of formatter functions or static methods as keys, fields they apply to as values
                    // a°) A NOT key is allowed to negate the condition
                    // b°) Boolean true means all fields, false means the formatter is not used
                    // c°) Strings or array of strings are allowed
                        // * regular expressions (delimited by "/") are used to filter field names
                        // * other strings are used to filter field types
                'formatters' => [
                    // Extract the part after the last "_" character
                    '\\Database\\Utility\\Formatter::formatSuffix' => '/_id$/',
                    // Trim the value
                    '\\Database\\Utility\\Formatter::formatTrim' => [ 'NOT' => 'binary'],
                    // Transform empty string to a NULL value
                    '\\Database\\Utility\\Formatter::formatNull' => true,
                    // Tries to parse an integer value using the current intl.default_locale value
                    '\\Database\\Utility\\Formatter::formatInteger' => ['integer', 'biginteger'],
                    // Tries to parse a decimal value using the current intl.default_locale value
                    '\\Database\\Utility\\Formatter::formatDecimal' => ['decimal', 'float', 'numeric']
                ]
            ]
        );
    // ...
}
```

### Code quality

[](#code-quality)

```
sudo bash -c "( rm -rf logs/quality ; find logs -type f -iname '*.log' -exec rm {} \;  ; find tmp -type f ! -name 'empty' -exec rm {} \; )"
sudo -u apache ant quality -f vendor/jmjjg/cakephp3-database/vendor/Jenkins/build.xml
```

###  Health Score

19

—

LowBetter than 9% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity49

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

3447d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/14168247?v=4)[Christian Buffin](/maintainers/jmjjg)[@jmjjg](https://github.com/jmjjg)

---

Top Contributors

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

---

Tags

validationdatabasecakephpmarshalling

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/jmjjg-cakephp3-database/health.svg)

```
[![Health](https://phpackages.com/badges/jmjjg-cakephp3-database/health.svg)](https://phpackages.com/packages/jmjjg-cakephp3-database)
```

###  Alternatives

[dereuromark/cakephp-databaselog

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

44172.5k2](/packages/dereuromark-cakephp-databaselog)[cakephp/bake

Bake plugin for CakePHP

11212.0M196](/packages/cakephp-bake)[dereuromark/cakephp-queue

The Queue plugin for CakePHP provides deferred task execution.

308954.9k25](/packages/dereuromark-cakephp-queue)[dereuromark/cakephp-ide-helper

CakePHP IdeHelper Plugin to improve auto-completion

1882.3M41](/packages/dereuromark-cakephp-ide-helper)[codezero/laravel-unique-translation

Check if a translated value in a JSON column is unique in the database.

1881.0M8](/packages/codezero-laravel-unique-translation)[dereuromark/cakephp-shim

A CakePHP plugin to shim applications between major framework versions.

401.1M22](/packages/dereuromark-cakephp-shim)

PHPackages © 2026

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