Created
February 13, 2017 15:28
-
-
Save jacricelli/e9893f3999e5d5091618d2942c559b44 to your computer and use it in GitHub Desktop.
Agregar opción 'last' a cada regla de validación si ésta no se ha definido
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
<?php | |
namespace App\Model\Validation; | |
use Cake\Validation\Validator; | |
/** | |
* [CustomValidator description] | |
*/ | |
class CustomValidator extends Validator | |
{ | |
/** | |
* Añade una nueva regla al conjunto de reglas de un campo | |
* | |
* @param string $field Nombre del campo | |
* @param array|string $name El alias para una única regla o un array para múltiples reglas | |
* @param array|\Cake\Validation\ValidationRule $rule La regla para agregar | |
* | |
* @return $this | |
*/ | |
public function add($field, $name, $rule = []) | |
{ | |
if (!is_array($name)) { | |
$rules = [$name => $rule]; | |
} else { | |
$rules = $name; | |
} | |
foreach ($rules as $name => $options) { | |
if (!isset($options['last'])) { | |
$rules[$name]['last'] = true; | |
} | |
} | |
return parent::add($field, $name, $rule); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment