Skip to content

Commit 5cd8760

Browse files
Merge pull request DavidePastore#38 from DavidePastore/update-respect-validation-package
Update respect validation package
2 parents fb506ff + de4fe44 commit 5cd8760

File tree

5 files changed

+736
-358
lines changed

5 files changed

+736
-358
lines changed

README.md

+3-27
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ A validation library for the Slim Framework. It internally uses [Respect/Validat
2121
- [JSON requests](#json-requests)
2222
- [XML requests](#xml-requests)
2323
- [Translate errors](#translate-errors)
24-
- [Use templates](#use-templates)
2524
- [Testing](#testing)
2625
- [Contributing](#contributing)
2726
- [Credits](#credits)
@@ -63,7 +62,7 @@ $app->get('/api/myEndPoint',function ($req, $res, $args) {
6362
//There are errors, read them
6463
$errors = $req->getAttribute('errors');
6564

66-
/* $errors contain:
65+
/* $errors contains:
6766
array(
6867
'username' => array(
6968
'"davidepastore" must have a length between 1 and 10',
@@ -108,7 +107,7 @@ $app->get('/foo', function ($req, $res, $args) {
108107
//There are errors, read them
109108
$errors = $req->getAttribute('errors');
110109

111-
/* $errors contain:
110+
/* $errors contains:
112111
array(
113112
'username' => array(
114113
'"davidepastore" must have a length between 1 and 10',
@@ -156,7 +155,7 @@ $app->get('/foo/{param}', function ($req, $res, $args) {
156155
//There are errors, read them
157156
$errors = $req->getAttribute('errors');
158157

159-
/* $errors contain:
158+
/* $errors contains:
160159
array(
161160
'param' => array(
162161
'"wrong" must be numeric',
@@ -322,29 +321,6 @@ $middleware = new \DavidePastore\Slim\Validation\Validation($validators, $transl
322321
$app->run();
323322
```
324323

325-
### Use templates
326-
327-
With the third parameter you can specify to use [templates][custom-messages].
328-
329-
```php
330-
use Respect\Validation\Validator as v;
331-
332-
$app = new \Slim\App();
333-
334-
//Create the validators
335-
$usernameValidator = v::alnum()->noWhitespace()->length(1, 10);
336-
$ageValidator = v::numeric()->positive()->between(1, 20);
337-
$validators = array(
338-
'hostname' => v::regex('/^[a-zA-Z]([-.a-zA-Z0-9]{0,61}[a-zA-Z0-9]){0,1}$/')->setTemplate('Hostname {{name}} is not valid')
339-
);
340-
341-
$middleware = new \DavidePastore\Slim\Validation\Validation($validators, null, array('useTemplate' => true));
342-
343-
// Register middleware for all routes or only for one...
344-
345-
$app->run();
346-
```
347-
348324

349325
## Testing
350326

composer.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"require": {
1313
"php": ">=5.5.0",
1414
"psr/http-message": "^1.0",
15-
"respect/validation": "^1.0"
15+
"respect/validation": "^1.1 >=1.1.23"
1616
},
1717
"require-dev": {
1818
"slim/slim": "~3.0",
@@ -29,5 +29,10 @@
2929
"psr-4": {
3030
"DavidePastore\\Slim\\Validation\\Tests\\": "tests"
3131
}
32+
},
33+
"config": {
34+
"platform": {
35+
"php": "5.5"
36+
}
3237
}
3338
}

0 commit comments

Comments
 (0)