[Solar-svn] Revision 3094
pmjones at solarphp.com
pmjones at solarphp.com
Fri Apr 11 07:04:33 CDT 2008
Solar_Filter
* [REF] Refactored data-element filtering out of applyChain() and into its own support method _applyChain().
* [CHG] Method _applyChain() now uses the locale key provided by the new Solar_Filter_Abstract::getInvalid() method, instead of only the method name being passed to _chainLocale().
Modified: trunk/Solar/Filter.php
===================================================================
--- trunk/Solar/Filter.php 2008-04-11 12:01:29 UTC (rev 3093)
+++ trunk/Solar/Filter.php 2008-04-11 12:04:26 UTC (rev 3094)
@@ -583,32 +583,8 @@
$this->setRequire(false);
}
- // run the filters for the data element
- foreach ($this->_chain_filters[$key] as $params) {
-
- // take the method name off the top of the params ...
- $method = array_shift($params);
-
- // ... and put the value in its place. we use the
- // $data[$key] instead of $val so that the data
- // array itself is updated, not the local-scope $val.
- array_unshift($params, $this->_data[$key]);
-
- // call the filtering method
- $result = $this->__call($method, $params);
-
- // what to do with the result?
- $type = strtolower(substr($method, 0, 8));
- if ($type == 'sanitize') {
- // retain the sanitized value
- $this->_data[$key] = $result;
- } elseif ($type == 'validate' && ! $result) {
- // a validation method failed; use the method name as
- // the locale translation key, converting from camelCase
- // to camel_Case, then to CAMEL_CASE.
- $this->_chain_invalid[$key][] = $this->_chainLocale($method);
- }
- }
+ // run the filters for each data element
+ $this->_applyChain($key);
}
// return the validation status; if not empty, at least one of the
@@ -619,6 +595,45 @@
/**
*
+ * Support method for [[applyChain()]] to apply all the filters on a
+ * single data element.
+ *
+ * @param string $key The data element key.
+ *
+ * @return void
+ *
+ */
+ protected function _applyChain($key)
+ {
+ foreach ($this->_chain_filters[$key] as $params) {
+
+ // take the method name off the top of the params ...
+ $method = array_shift($params);
+
+ // ... and put the value in its place. we use the
+ // $data[$key] instead of $val so that the data
+ // array itself is updated, not the local-scope $val.
+ array_unshift($params, $this->_data[$key]);
+
+ // call the filtering method
+ $result = $this->__call($method, $params);
+
+ // what to do with the result?
+ $type = strtolower(substr($method, 0, 8));
+ if ($type == 'sanitize') {
+ // retain the sanitized value
+ $this->_data[$key] = $result;
+ } elseif ($type == 'validate' && ! $result) {
+ // a validation method failed, get the locale key for the
+ // invalid message and translate it.
+ $invalid = $this->getFilter($method)->getInvalid();
+ $this->_chain_invalid[$key][] = $this->_chainLocale($invalid);
+ }
+ }
+ }
+
+ /**
+ *
* Uses the chain locale object to get translations before falling back
* to this object for locale.
*
@@ -630,12 +645,6 @@
*/
protected function _chainLocale($key)
{
- // 'validatePregReplace' => 'invalidPregReplace'
- $key = 'invalid' . substr($key, 8);
-
- // 'validatePregReplace' => 'INVALID_PREG_REPLACE'
- $key = strtoupper(preg_replace('/([a-z])([A-Z])/', '$1_$2', $key));
-
// the translated message
$msg = null;
More information about the Solar-svn
mailing list