2017 © Pedro Peláez
 

cakephp-plugin cakephp-validation-exposer

Easily expose your CakePHP 3.x application validation rules

image

alt3/cakephp-validation-exposer

Easily expose your CakePHP 3.x application validation rules

  • Sunday, September 4, 2016
  • by alt3
  • Repository
  • 2 Watchers
  • 9 Stars
  • 165 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 2 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

cakephp-validation-exposer

Build Status StyleCI Status codecov Total Downloads License, (*1)

Easily expose your CakePHP 3.x application validation rules., (*2)

Abandoned repository, (*3)

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:, (*4)

  • 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

  1. Install the plugin using composer:, (*5)

    composer require alt3/cakephp-validation-exposer:"^1.0"
    
  2. To enable the plugin either run the following command:, (*6)

    bin/cake plugin load Alt3/ValidationExposer
    

    or manually add the following line to your config/bootstrap.php file:, (*7)

    Plugin::load('Alt3/ValidationExposer');
    

Usage

  1. Create a ValidationExposer object anywhere in your application
  2. Call the rules() method
  3. Present the returned array with validation information any way you see fit

API example

<?php
use Alt3\ValidationExposer\Lib\ValidationExposer;

class SystemController extends AppController
{

    public function validationInfo()
    {
        $validationExposer = new ValidationExposer([
            'excludedTables' => [
                'table_to_skip' // this table will not be processed
            ],
            'hiddenRuleParts' =>
                'message' // do not show this part inside the `rules` array
            ]
        ]);

        $this->set([
            'success' => true,
            'data' => $validationExposer->rules(),
            '_serialize' => ['success', 'data']
        ]);
    }
}

Configuration

Any table found in the excludedTables configuration array will not be searched for validation information., (*8)

Please note that the phinxlog table is excluded by default., (*9)

Add one or more of the following fields to the hiddenRuleParts configuration array and they will not appear in the result set:, (*10)

  • name: holds the rule name
  • rule: holds the internal rule name (numeric, unique, etc)
  • message: holds the validation message
  • parts: 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:, (*11)

```php [users] => Array ( [id] => Array ( [requiredFor] => [allowedEmptyFor] => create [rules] => Array ( [0] => Array ( [name] => NUMERIC [rule] => numeric [message] => ), (*12)

                )

        )

    [email] => Array
        (
            [requiredFor] => create
            [allowedEmptyFor] =>
            [rules] => Array
                (
                    [0] => Array
                        (
                            [name] => FORMAT
                            [rule] => email
                            [message] => Invalid email address format.
                        )

                    [1] => Array
                        (
                            [name] => UNIQUE
                            [rule] => validateUnique
                            [message] => This email address already exists
                        )

                )

        )

    [password] => Array
        (
            [requiredFor] => create
            [allowedEmptyFor] =>
            [rules] => Array
                (
                    [0] => Array
                        (
                            [name] => MIN_LENGTH
                            [rule] => minLength
                            [message] => Your password must be at least {minLength} characters.
                            [pass] => Array
                                (
                                    [0] => 8
                                )

                        )

                    [1] => Array
                        (
                            [name] => MAX_LENGTH
                            [rule] => maxLength
                            [message] => Your password cannot exceed {maxLength} characters
                            [pass] => Array
                                (
                                    [0] => 255
                                )

                        )
                )
        )
    )

### `tables()` Use the `tables()` method to produce a flat array with all tables included in validation aggregation. ```php ( [0] => cocktails [1] => liquors [2] => users )

excludedTables()

Use the excludedTables() method to produce a flat array with tables not included in validation aggregation., (*13)

```php ( [0] => phinxlog [1] => staging ) ````, (*14)

Contribute

Before submitting a PR make sure:, (*15)

The Versions

04/09 2016

dev-master

9999999-dev

Easily expose your CakePHP 3.x application validation rules

  Sources   Download

MIT

The Requires

 

22/05 2016

1.0.2

1.0.2.0

Easily expose your CakePHP 3.x application validation rules

  Sources   Download

MIT

The Requires

 

21/05 2016

0.0.2

0.0.2.0

Easily expose your CakePHP 3.x application validation rules

  Sources   Download

MIT

The Requires

 

21/05 2016

1.0.1

1.0.1.0

Easily expose your CakePHP 3.x application validation rules

  Sources   Download

MIT

The Requires

 

21/05 2016

0.0.1

0.0.1.0

Easily expose your CakePHP 3.x application validation rules

  Sources   Download

MIT

The Requires

 

21/05 2016

0.1

0.1.0.0

Easily expose your CakePHP 3.x application validation rules

  Sources   Download

MIT

The Requires

 

21/05 2016

1.0.0

1.0.0.0

Easily expose your CakePHP 3.x application validation rules

  Sources   Download

MIT

The Requires