cakephp-postgres
Description
CakePHP 3 plugin that provides classes for adding default validation rules from the database table schema., (*1)
Caching is enabled by default but can be disabled in the configuration or at run-time., (*2)
Tested with CakePHP 3.1.0, 3.2.2., (*3)
Main classes
AutovalidateBehavior reads various informations from the database table schema... and automatically adds those validation rules to the default ones., (*4)
Setup
Assuming the plugin is installed under plugins/Postgres., (*5)
Add the following to config/bootstrap.php:, (*6)
Plugin::load('Postgres', ['autoload' => true, 'bootstrap' => true]);
[
// ...
'Datasources.default.driver' => 'Postgres\Database\Driver\Postgres',
// ...
'Datasources.test.driver' => 'Postgres\Database\Driver\Postgres'
// ...
Usage
The following code should be added to your table classes, inside the initialize() method., (*7)
Note that NULL and boolean TRUE and are equivalent as configuration values., (*8)
public function initialize(array $config)
{
// ...
$this->addBehavior('PostgresAutovalidate',
[
'className' => 'Postgres.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 ?
'cache' => null,
// 3°) Domain to use for error messages
'domain' => 'postgres'
]
);
// ...
}
Code quality
sudo bash -c "( rm -r logs/quality ; find . -type f -regex '^\./\(logs/.*\.log\|tmp/.*\)$' ! -name 'empty' -exec rm {} \; )"
sudo -u apache ant quality -f vendor/jmjjg/cakephp3-postgres/vendor/Jenkins/build.xml