From 9afff835780cf874afafa79a43edb34afab736af Mon Sep 17 00:00:00 2001 From: Eriksen Costa Paixão Date: Tue, 23 Mar 2010 22:40:15 +0000 Subject: [PATCH] Atualizada interface de CoreExt_Validate_Abstract. Método {{{_getOption()}}} protected agora é public, com a assinatura {{{getOption()}}} --- ieducar/lib/CoreExt/Validate/Abstract.php | 8 ++++---- ieducar/lib/CoreExt/Validate/Choice.php | 6 +++--- ieducar/lib/CoreExt/Validate/Numeric.php | 8 ++++---- ieducar/lib/CoreExt/Validate/String.php | 8 ++++---- ieducar/modules/FormulaMedia/Validate/Formula.php | 6 +++--- ieducar/tests/unit/CoreExt/Validate/ValidateTest.php | 10 ++++++++++ 6 files changed, 28 insertions(+), 18 deletions(-) diff --git a/ieducar/lib/CoreExt/Validate/Abstract.php b/ieducar/lib/CoreExt/Validate/Abstract.php index f00dd87..0f50364 100644 --- a/ieducar/lib/CoreExt/Validate/Abstract.php +++ b/ieducar/lib/CoreExt/Validate/Abstract.php @@ -140,7 +140,7 @@ abstract class CoreExt_Validate_Abstract implements CoreExt_Validate_Interface * @param string $key * @return mixed|NULL */ - protected function _getOption($key) + public function getOption($key) { return $this->_hasOption($key) ? $this->_options[$key] : NULL; } @@ -161,13 +161,13 @@ abstract class CoreExt_Validate_Abstract implements CoreExt_Validate_Interface $this->_value = $value; $value = $this->_sanitize($value); - if (TRUE == $this->_getOption('trim')) { + if (TRUE == $this->getOption('trim')) { $value = trim($value); } $this->_sanitized = $value; - if (TRUE == $this->_getOption('required') && $this->_isEmpty($value)) { + if (TRUE == $this->getOption('required') && $this->_isEmpty($value)) { throw new Exception($this->_requiredMessage); } @@ -244,7 +244,7 @@ abstract class CoreExt_Validate_Abstract implements CoreExt_Validate_Interface */ protected function _getErrorMessage($key, array $options = array()) { - $message = $this->_getOption($key); + $message = $this->getOption($key); if (is_array($message)) { // Verifica o tipo de @value para determinar a quantidade de $count diff --git a/ieducar/lib/CoreExt/Validate/Choice.php b/ieducar/lib/CoreExt/Validate/Choice.php index 54e6b62..065f1f9 100644 --- a/ieducar/lib/CoreExt/Validate/Choice.php +++ b/ieducar/lib/CoreExt/Validate/Choice.php @@ -69,9 +69,9 @@ class CoreExt_Validate_Choice extends CoreExt_Validate_Abstract { if ($this->_hasOption('choices')) { $value = $this->_getStringArray($value); - $choices = $this->_getStringArray($this->_getOption('choices')); + $choices = $this->_getStringArray($this->getOption('choices')); - if ($this->_hasOption('multiple') && FALSE == $this->_getOption('multiple')) { + if ($this->_hasOption('multiple') && FALSE == $this->getOption('multiple')) { if (in_array($value, $choices, TRUE)) { return TRUE; } @@ -83,7 +83,7 @@ class CoreExt_Validate_Choice extends CoreExt_Validate_Abstract } throw new Exception($this->_getErrorMessage( 'multiple_error', - array('@value' => array_diff($value, $this->_getOption('choices')))) + array('@value' => array_diff($value, $this->getOption('choices')))) ); } } diff --git a/ieducar/lib/CoreExt/Validate/Numeric.php b/ieducar/lib/CoreExt/Validate/Numeric.php index 8de3149..5cbba9a 100644 --- a/ieducar/lib/CoreExt/Validate/Numeric.php +++ b/ieducar/lib/CoreExt/Validate/Numeric.php @@ -72,16 +72,16 @@ class CoreExt_Validate_Numeric extends CoreExt_Validate_Abstract $value = floatval($value); if ($this->_hasOption('min') && - $value < floatval($this->_getOption('min'))) { + $value < floatval($this->getOption('min'))) { throw new Exception($this->_getErrorMessage('min_error', array( - '@value' => $value, '@min' => $this->_getOption('min') + '@value' => $value, '@min' => $this->getOption('min') ))); } if ($this->_hasOption('max') && - $value > floatval($this->_getOption('max'))) { + $value > floatval($this->getOption('max'))) { throw new Exception($this->_getErrorMessage('max_error', array( - '@value' => $value, '@max' => $this->_getOption('max') + '@value' => $value, '@max' => $this->getOption('max') ))); } diff --git a/ieducar/lib/CoreExt/Validate/String.php b/ieducar/lib/CoreExt/Validate/String.php index a94eafd..54e4d76 100644 --- a/ieducar/lib/CoreExt/Validate/String.php +++ b/ieducar/lib/CoreExt/Validate/String.php @@ -62,15 +62,15 @@ class CoreExt_Validate_String extends CoreExt_Validate_Abstract { $length = strlen($value); - if ($this->_hasOption('min') && $length < $this->_getOption('min')) { + if ($this->_hasOption('min') && $length < $this->getOption('min')) { throw new Exception($this->_getErrorMessage('min_error', - array('@value' => $this->getSanitizedValue(), '@min' => $this->_getOption('min'))) + array('@value' => $this->getSanitizedValue(), '@min' => $this->getOption('min'))) ); } - if ($this->_hasOption('max') && $length > $this->_getOption('max')) { + if ($this->_hasOption('max') && $length > $this->getOption('max')) { throw new Exception($this->_getErrorMessage('max_error', - array('@value' => $this->getSanitizedValue(), '@max' => $this->_getOption('max'))) + array('@value' => $this->getSanitizedValue(), '@max' => $this->getOption('max'))) ); } diff --git a/ieducar/modules/FormulaMedia/Validate/Formula.php b/ieducar/modules/FormulaMedia/Validate/Formula.php index 79059b7..d8a56fd 100644 --- a/ieducar/modules/FormulaMedia/Validate/Formula.php +++ b/ieducar/modules/FormulaMedia/Validate/Formula.php @@ -132,10 +132,10 @@ class FormulaMedia_Validate_Formula extends CoreExt_Validate_Abstract $tokensAvailable = array(); if ($this->_hasOption('excludeToken') && - is_array($this->_getOption('excludeToken')) && - 0 < count($this->_getOption('excludeToken')) + is_array($this->getOption('excludeToken')) && + 0 < count($this->getOption('excludeToken')) ) { - $excludeToken = $this->_getOption('excludeToken'); + $excludeToken = $this->getOption('excludeToken'); foreach ($tokens as $token) { if (!in_array($token, $excludeToken)) { $tokensAvailable[] = $token; diff --git a/ieducar/tests/unit/CoreExt/Validate/ValidateTest.php b/ieducar/tests/unit/CoreExt/Validate/ValidateTest.php index 0ffa936..446b6e6 100644 --- a/ieducar/tests/unit/CoreExt/Validate/ValidateTest.php +++ b/ieducar/tests/unit/CoreExt/Validate/ValidateTest.php @@ -60,6 +60,16 @@ class CoreExt_ValidateTest extends UnitBaseTest $this->_validator->setOptions(array('invalidOption' => TRUE)); } + public function testConfiguraOpcaoDoValidator() + { + $this->_validator->setOptions(array('required' => FALSE)); + + $options = $this->_validator->getOptions(); + $this->assertFalse($options['required']); + + $this->assertFalse($this->_validator->getOption('required')); + } + /** * @expectedException Exception */ -- libgit2 0.21.2