add option to pass config to ValidationComponent

This commit is contained in:
oliver 2015-05-14 18:48:18 +02:00
commit 6e96556b0e

View file

@ -82,20 +82,25 @@
* @param array $index Names of parameter to validate and to validate against * @param array $index Names of parameter to validate and to validate against
* @return mixed True or the parameter with settings the validation failed on * @return mixed True or the parameter with settings the validation failed on
*/ */
public function validateParam($params, $index) public function validateParam($params, $index, $config=null)
{ {
// Check onfig
if(is_null($config)) {
$config = $this->config;
}
// Check parameter // Check parameter
if(!array_key_exists($index, $params)) { if(!array_key_exists($index, $params)) {
throw new \nre\exceptions\ParamsNotValidException($index); throw new \nre\exceptions\ParamsNotValidException($index);
} }
// Check settings // Check settings
if(!array_key_exists($index, $this->config)) { if(!array_key_exists($index, $config)) {
return true; return true;
} }
// Validate parameter and return result // Validate parameter and return result
return $this->validate($params[$index], $this->config[$index]); return $this->validate($params[$index], $config[$index]);
} }
@ -106,12 +111,12 @@
* @param array $indices Names of parameters to validate and to validate against * @param array $indices Names of parameters to validate and to validate against
* @return mixed True or the parameters with settings the validation failed on * @return mixed True or the parameters with settings the validation failed on
*/ */
public function validateParams($params, $indices) public function validateParams($params, $indices, $config=null)
{ {
// Validate parameters // Validate parameters
$validation = true; $validation = true;
foreach($indices as $index) { foreach($indices as $index) {
$validation = $this->addValidationResults($validation, $index, $this->validateParam($params, $index)); $validation = $this->addValidationResults($validation, $index, $this->validateParam($params, $index, $config));
} }