Download the PHP package alt3/cakephp-validation-exposer without Composer
On this page you can find all versions of the php package alt3/cakephp-validation-exposer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download alt3/cakephp-validation-exposer
More information about alt3/cakephp-validation-exposer
Files in alt3/cakephp-validation-exposer
Package cakephp-validation-exposer
Short Description Easily expose your CakePHP 3.x application validation rules
License MIT
Informations about the package cakephp-validation-exposer
cakephp-validation-exposer
Easily expose your CakePHP 3.x application validation rules.
Why use it?
Exposing your application's validation rules can be very useful for e.g. completely separated frontend applications. Imagine a React frontend for your API being able to realtime configure (very fast) local validation rules exactly matching your CakePHP API backend's validation rules. Some benefits:
- no more mismatches between local and backend validations
- backend validation changes instantly applied in frontend application
- no more fire-and-hope POSTing of data
- less local 412 validation errors
Requirements
- CakePHP 3.0+
Installation
-
Install the plugin using composer:
-
To enable the plugin either run the following command:
or manually add the following line to your
config/bootstrap.php
file:
Usage
- Create a
ValidationExposer
object anywhere in your application - Call the
rules()
method - Present the returned array with validation information any way you see fit
API example
Configuration
Any table found in the excludedTables
configuration array will not be
searched for validation information.
Please note that the
phinxlog
table is excluded by default.
Add one or more of the following fields to the hiddenRuleParts
configuration
array and they will not appear in the result set:
name
: holds the rule namerule
: holds the internal rule name (numeric, unique, etc)message
: holds the validation messageparts
: holds arguments passed to the validation rule
Methods
rules()
Use the rules()
method to produce a hash containing all validation
information found in your application structured similarly to shown below:
`
tables()
Use the tables()
method to produce a flat array with all tables included
in validation aggregation.
`
excludedTables()
Use the excludedTables()
method to produce a flat array with tables not
included in validation aggregation.
`
Contribute
Before submitting a PR make sure:
- PHPUnit and CakePHP Code Sniffer tests pass
- Coveralls Code Coverage remains at 100%