From 6e96556b0ebfa216c875ce72549d86865bb38d3e Mon Sep 17 00:00:00 2001 From: oliver Date: Thu, 14 May 2015 18:48:18 +0200 Subject: [PATCH] add option to pass config to ValidationComponent --- controllers/components/ValidationComponent.inc | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/controllers/components/ValidationComponent.inc b/controllers/components/ValidationComponent.inc index 0a639bf0..c9f6d110 100644 --- a/controllers/components/ValidationComponent.inc +++ b/controllers/components/ValidationComponent.inc @@ -82,20 +82,25 @@ * @param array $index Names of parameter to validate and to validate against * @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 if(!array_key_exists($index, $params)) { throw new \nre\exceptions\ParamsNotValidException($index); } // Check settings - if(!array_key_exists($index, $this->config)) { + if(!array_key_exists($index, $config)) { return true; } // 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 * @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 $validation = true; foreach($indices as $index) { - $validation = $this->addValidationResults($validation, $index, $this->validateParam($params, $index)); + $validation = $this->addValidationResults($validation, $index, $this->validateParam($params, $index, $config)); }