Skip to content

Commit

Permalink
Allow customizing default validator class.
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Jun 12, 2015
1 parent 46c3106 commit bb0edbb
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Validation/ValidatorAwareTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
namespace Cake\Validation;

use Cake\Event\EventDispatcherInterface;
use Cake\Validation\Validator;

/**
* A trait that provides methods for building and
Expand All @@ -36,6 +35,14 @@
*/
trait ValidatorAwareTrait
{

/**
* Validator class.
*
* @var string
*/
protected $_validatorClass = '\Cake\Validation\Validator';

/**
* A list of validation objects indexed by name
*
Expand Down Expand Up @@ -95,7 +102,7 @@ public function validator($name = null, Validator $validator = null)
}

if ($validator === null) {
$validator = new Validator();
$validator = new $this->_validatorClass;
$validator = $this->{'validation' . ucfirst($name)}($validator);
if ($this instanceof EventDispatcherInterface) {
$this->dispatchEvent('Model.buildValidator', compact('validator', 'name'));
Expand Down

0 comments on commit bb0edbb

Please sign in to comment.