-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
57 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
theme: jekyll-theme-cayman |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,29 +5,28 @@ | |
"authors": [ | ||
{ | ||
"name": "Anderson Andrade", | ||
"homepage": "http://andersonandra.de", | ||
"email": "[email protected]", | ||
"role":"Developer" | ||
"role": "Developer" | ||
} | ||
], | ||
"homepage": "http://andersao.github.io/laravel-validation", | ||
"support": { | ||
"email": "[email protected]", | ||
"issues":"https://github.com/andersao/laravel-validator/issues", | ||
"wiki":"https://github.com/andersao/laravel-validator", | ||
"source":"https://github.com/andersao/laravel-validator" | ||
"issues":"https://github.com/andersao/laravel-validation/issues", | ||
"wiki":"https://github.com/andersao/laravel-validation", | ||
"source":"https://github.com/andersao/laravel-validation", | ||
"docs": "http://andersao.github.io/laravel-validation" | ||
}, | ||
"require": { | ||
"illuminate/support": "~5.0|~5.1|~5.2", | ||
"illuminate/validation": "~5.0|~5.1|~5.2" | ||
"php": ">=5.4.0", | ||
"illuminate/support": "~5.4", | ||
"illuminate/validation": "~5.4" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Prettus\\Validator\\": "src/Prettus/Validator/" | ||
} | ||
}, | ||
"extra": { | ||
"branch-alias": { | ||
"dev-develop": "1.2-dev" | ||
} | ||
}, | ||
"minimum-stability": "stable" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,9 +7,10 @@ | |
/** | ||
* Class AbstractValidator | ||
* @package Prettus\Validator | ||
* @author Anderson Andrade <[email protected]> | ||
*/ | ||
abstract class AbstractValidator implements ValidatorInterface { | ||
|
||
abstract class AbstractValidator implements ValidatorInterface | ||
{ | ||
/** | ||
* @var int | ||
*/ | ||
|
@@ -64,7 +65,8 @@ abstract class AbstractValidator implements ValidatorInterface { | |
* @param $id | ||
* @return $this | ||
*/ | ||
public function setId($id){ | ||
public function setId($id) | ||
{ | ||
$this->id = $id; | ||
return $this; | ||
} | ||
|
@@ -108,7 +110,7 @@ public function errorsBag() | |
* @param string $action | ||
* @return boolean | ||
*/ | ||
abstract public function passes( $action = null ); | ||
abstract public function passes($action = null); | ||
|
||
/** | ||
* Pass the data and the rules to the validator or throws ValidatorException | ||
|
@@ -119,8 +121,8 @@ abstract public function passes( $action = null ); | |
*/ | ||
public function passesOrFail($action = null) | ||
{ | ||
if( !$this->passes($action) ){ | ||
throw new ValidatorException( $this->errorsBag() ); | ||
if (!$this->passes($action)) { | ||
throw new ValidatorException($this->errorsBag()); | ||
} | ||
|
||
return true; | ||
|
@@ -134,11 +136,11 @@ public function passesOrFail($action = null) | |
* @param null $action | ||
* @return array | ||
*/ | ||
public function getRules($action = null){ | ||
|
||
public function getRules($action = null) | ||
{ | ||
$rules = $this->rules; | ||
|
||
if( isset($this->rules[$action]) ){ | ||
if (isset($this->rules[$action])) { | ||
$rules = $this->rules[$action]; | ||
} | ||
|
||
|
@@ -162,14 +164,15 @@ public function setRules(array $rules) | |
* | ||
* @return array | ||
*/ | ||
public function getMessages(){ | ||
|
||
public function getMessages() | ||
{ | ||
return $this->messages; | ||
} | ||
|
||
/** | ||
* Set Custom error messages for Validation | ||
* | ||
* @param array $messages | ||
* @return $this | ||
*/ | ||
public function setMessages(array $messages) | ||
|
@@ -183,14 +186,15 @@ public function setMessages(array $messages) | |
* | ||
* @return array | ||
*/ | ||
public function getAttributes(){ | ||
|
||
public function getAttributes() | ||
{ | ||
return $this->attributes; | ||
} | ||
|
||
/** | ||
* Set Custom error attributes for Validation | ||
* | ||
* @param array $attributes | ||
* @return $this | ||
*/ | ||
public function setAttributes(array $attributes) | ||
|
@@ -208,33 +212,28 @@ public function setAttributes(array $attributes) | |
*/ | ||
protected function parserValidationRules($rules, $id = null) | ||
{ | ||
|
||
if($id === null) | ||
{ | ||
if (null === $id) { | ||
return $rules; | ||
} | ||
|
||
array_walk($rules, function(&$rules, $field) use ($id) | ||
{ | ||
if(!is_array($rules)) | ||
{ | ||
array_walk($rules, function (&$rules, $field) use ($id) { | ||
if (!is_array($rules)) { | ||
$rules = explode("|", $rules); | ||
} | ||
|
||
foreach($rules as $ruleIdx => $rule) | ||
{ | ||
foreach ($rules as $ruleIdx => $rule) { | ||
// get name and parameters | ||
@list($name, $params) = array_pad(explode(":", $rule), 2, null); | ||
|
||
// only do someting for the unique rule | ||
if(strtolower($name) != "unique") { | ||
if (strtolower($name) != "unique") { | ||
continue; // continue in foreach loop, nothing left to do here | ||
} | ||
|
||
$p = array_map("trim", explode(",", $params)); | ||
|
||
// set field name to rules key ($field) (laravel convention) | ||
if(!isset($p[1])) { | ||
if (!isset($p[1])) { | ||
$p[1] = $field; | ||
} | ||
|
||
|
@@ -248,5 +247,4 @@ protected function parserValidationRules($rules, $id = null) | |
|
||
return $rules; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,10 @@ | |
/** | ||
* Interface ValidatorInterface | ||
* @package Prettus\Validator\Contracts | ||
* @author Anderson Andrade <[email protected]> | ||
*/ | ||
interface ValidatorInterface { | ||
|
||
interface ValidatorInterface | ||
{ | ||
const RULE_CREATE = 'create'; | ||
const RULE_UPDATE = 'update'; | ||
|
||
|
@@ -34,8 +35,7 @@ public function with(array $input); | |
* @param string $action | ||
* @return boolean | ||
*/ | ||
public function passes( $action = null ); | ||
|
||
public function passes($action = null); | ||
|
||
/** | ||
* Pass the data and the rules to the validator or throws ValidatorException | ||
|
@@ -44,7 +44,7 @@ public function passes( $action = null ); | |
* @param string $action | ||
* @return boolean | ||
*/ | ||
public function passesOrFail( $action = null ); | ||
public function passesOrFail($action = null); | ||
|
||
/** | ||
* Errors | ||
|
@@ -77,4 +77,4 @@ public function setRules(array $rules); | |
* @return array | ||
*/ | ||
public function getRules($action = null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,9 +7,10 @@ | |
/** | ||
* Class ValidatorException | ||
* @package Prettus\Validator\Exceptions | ||
* @author Anderson Andrade <[email protected]> | ||
*/ | ||
class ValidatorException extends \Exception implements Jsonable, Arrayable { | ||
|
||
class ValidatorException extends \Exception implements Jsonable, Arrayable | ||
{ | ||
/** | ||
* @var MessageBag | ||
*/ | ||
|
@@ -18,14 +19,16 @@ class ValidatorException extends \Exception implements Jsonable, Arrayable { | |
/** | ||
* @param MessageBag $messageBag | ||
*/ | ||
public function __construct(MessageBag $messageBag){ | ||
public function __construct(MessageBag $messageBag) | ||
{ | ||
$this->messageBag = $messageBag; | ||
} | ||
|
||
/** | ||
* @return MessageBag | ||
*/ | ||
public function getMessageBag(){ | ||
public function getMessageBag() | ||
{ | ||
return $this->messageBag; | ||
} | ||
|
||
|
@@ -52,5 +55,4 @@ public function toJson($options = 0) | |
{ | ||
return json_encode($this->toArray(), $options); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
<?php namespace Prettus\Validator; | ||
|
||
use Illuminate\Validation\Factory; | ||
use Illuminate\Contracts\Validation\Factory; | ||
|
||
/** | ||
* Class LaravelValidator | ||
* @package Prettus\Validator | ||
* @author Anderson Andrade <[email protected]> | ||
*/ | ||
class LaravelValidator extends AbstractValidator { | ||
|
||
class LaravelValidator extends AbstractValidator | ||
{ | ||
/** | ||
* Validator | ||
* | ||
|
@@ -18,7 +19,7 @@ class LaravelValidator extends AbstractValidator { | |
/** | ||
* Construct | ||
* | ||
* @param \Illuminate\Validation\Factory $validator | ||
* @param \Illuminate\Contracts\Validation\Factory $validator | ||
*/ | ||
public function __construct(Factory $validator) | ||
{ | ||
|
@@ -38,13 +39,11 @@ public function passes($action = null) | |
$attributes = $this->getAttributes(); | ||
$validator = $this->validator->make($this->data, $rules, $messages, $attributes); | ||
|
||
if( $validator->fails() ) | ||
{ | ||
if ($validator->fails()) { | ||
$this->errors = $validator->messages(); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
} | ||
} |