
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
github.com/alt3/cakephp-validation-exposer
Easily expose your CakePHP 3.x application validation rules.
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:
Install the plugin using composer:
composer require alt3/cakephp-validation-exposer:"^1.0"
To enable the plugin either run the following command:
bin/cake plugin load Alt3/ValidationExposer
or manually add the following line to your config/bootstrap.php
file:
Plugin::load('Alt3/ValidationExposer');
ValidationExposer
object anywhere in your applicationrules()
method<?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']
]);
}
}
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 rulerules()
Use the rules()
method to produce a hash containing all validation
information found in your application structured similarly to shown below:
[users] => Array
(
[id] => Array
(
[requiredFor] =>
[allowedEmptyFor] => create
[rules] => Array
(
[0] => Array
(
[name] => NUMERIC
[rule] => numeric
[message] =>
)
)
)
[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.
(
[0] => cocktails
[1] => liquors
[2] => users
)
excludedTables()
Use the excludedTables()
method to produce a flat array with tables not
included in validation aggregation.
(
[0] => phinxlog
[1] => staging
)
Before submitting a PR make sure:
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.