@@ -39,28 +39,28 @@ require 'vendor/autoload.php'
3939
4040``` php
4141<?php
42- $rules = array(
43- 'name' => array(
42+ $rules = [
43+ 'name' => [
4444 'required',
4545 'alpha',
4646 'max_length(50)'
47- ) ,
48- 'age' => array(
47+ ] ,
48+ 'age' => [
4949 'required',
5050 'integer',
51- ) ,
52- 'email' => array(
51+ ] ,
52+ 'email' => [
5353 'required',
5454 'email'
55- ) ,
56- 'password' => array(
55+ ] ,
56+ 'password' => [
5757 'required',
5858 'equals(:password_verify)'
59- ) ,
60- 'password_verify' => array(
59+ ] ,
60+ 'password_verify' => [
6161 'required'
62- )
63- ) ;
62+ ]
63+ ] ;
6464$validation_result = SimpleValidator\Validator::validate($_POST, $rules);
6565if ($validation_result->isSuccess() == true) {
6666 echo "validation ok";
@@ -77,8 +77,8 @@ Anonymous functions make the custom validations easier to be implemented.
7777### Example
7878
7979``` php
80- $rules = array(
81- 'id' => array(
80+ $rules = [
81+ 'id' => [
8282 'required',
8383 'integer',
8484 'post_exists' => function($input) {
@@ -92,8 +92,8 @@ $rules = array(
9292 return true;
9393 return false;
9494 }
95- )
96- ) ;
95+ ]
96+ ] ;
9797```
9898
9999and you need to add an error text for your rule to the error file (default: errors/en.php).
@@ -105,18 +105,18 @@ and you need to add an error text for your rule to the error file (default: erro
105105or add a custom error text for that rule
106106
107107``` php
108- $validation_result->customErrors(array(
108+ $validation_result->customErrors([
109109 'post_exists' => 'Post does not exist'
110- ) );
110+ ] );
111111```
112112
113113### Another example to understand scoping issue
114114
115115``` php
116116// my local variable
117117$var_to_compare = "1234";
118- $rules = array(
119- 'password' => array(
118+ $rules = [
119+ 'password' => [
120120 'required',
121121 'integer',
122122 // pass my local variable to anonymous function
@@ -125,8 +125,8 @@ $rules = array(
125125 return true;
126126 return false;
127127 }
128- )
129- ) ;
128+ ]
129+ ] ;
130130```
131131
132132## Custom Validators
@@ -170,21 +170,21 @@ class MyValidator extends \SimpleValidator\Validator {
170170** Create an error file:**
171171
172172``` php
173- return array(
173+ return [
174174 'is_awesome' => 'the :attribute is not awesome'
175175 // error text for url is already defined in default error text file you don't have to define it here, but optionally you can
176- ) ;
176+ ] ;
177177```
178178
179179And then, call the ` validate ` method.
180180
181181``` php
182- $rules = array(
183- 'website' => array(
182+ $rules = [
183+ 'website' => [
184184 'is_awesome',
185185 'url'
186- )
187- )
186+ ]
187+ ];
188188$validation_result = MyValidator::validate($_POST, $rules);
189189```
190190
@@ -193,14 +193,14 @@ $validation_result = MyValidator::validate($_POST, $rules);
193193A rule can have multiple parameters. An example:
194194
195195``` php
196- $rule = array(
197- 'id' => array(
196+ $rule = [
197+ 'id' => [
198198 'rule1(:input1,:input2,2,5,:input3)' => function($input, $input1, $input2, $value1, $value2, $input3) {
199199 // validation here
200200 }
201- ) ,
201+ ] ,
202202 // and so on..
203- )
203+ ];
204204
205205
206206```
@@ -219,7 +219,7 @@ $validation_result->getErrors('es');
219219You can add custom errors using customErrors method.
220220#### Examples:
221221``` php
222- $validation_result->customErrors(array(
222+ $validation_result->customErrors([
223223 // input_name.rule => error text
224224 'website.required' => 'We need to know your web site',
225225 // rule => error text
@@ -228,17 +228,17 @@ $validation_result->customErrors(array(
228228 'email_addr.email' => 'Email should be valid',
229229 'email_addr.min_length' => 'Hey! Email is shorter than :params(0)',
230230 'min_length' => ':attribute must be longer than :params(0)'
231- ) );
231+ ] );
232232```
233233## Naming Inputs
234234
235235``` php
236- $naming => array(
236+ $naming => [
237237 'name' => 'Name',
238238 'url' => 'Web Site',
239239 'password' => 'Password',
240240 'password_verify' => 'Password Verification'
241- ) ;
241+ ] ;
242242$validation_result = SimpleValidator\Validator::validate($_POST, $rules, $naming);
243243```
244244#### Output sample:
0 commit comments