Skip to content

Commit

Permalink
Added support for defaultProviders to Validator
Browse files Browse the repository at this point in the history
  • Loading branch information
lilHermit committed Mar 6, 2017
1 parent 4957e10 commit 0b533e4
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/Validation/Validator.php
Expand Up @@ -52,6 +52,13 @@ class Validator implements ArrayAccess, IteratorAggregate, Countable
*/
protected $_providers = [];

/**
* An associative array of objects or classes used as a default provider list
*
* @var array
*/
private static $_defaultProviders = [];

/**
* Contains the validation messages associated with checking the presence
* for each corresponding field.
Expand Down Expand Up @@ -82,6 +89,7 @@ class Validator implements ArrayAccess, IteratorAggregate, Countable
public function __construct()
{
$this->_useI18n = function_exists('__d');
$this->_providers = self::$_defaultProviders;
}

/**
Expand Down Expand Up @@ -210,6 +218,43 @@ public function getProvider($name)
return $this->_providers[$name];
}

/**
* Returns the default provider stored under that name if it exists.
*
* @param string $name The name under which the provider should be retrieved.
* @return object|string|null
*/
public static function getDefaultProvider($name)
{
if (isset(self::$_defaultProviders[$name])) {
return self::$_defaultProviders[$name];
}

return null;
}

/**
* Associates an object to a name so it can be used as a default provider.
*
* @param string $name The name under which the provider should be set.
* @param object|string $object Provider object or class name.
* @return void
*/
public static function addDefaultProvider($name, $object)
{
self::$_defaultProviders[$name] = $object;
}

/**
* Get the list of default providers.
*
* @return array
*/
public static function getDefaultProviders()
{
return array_keys(self::$_defaultProviders);
}

/**
* Associates an object to a name so it can be used as a provider. Providers are
* objects or class names that can contain methods used during validation of for
Expand Down

0 comments on commit 0b533e4

Please sign in to comment.