[Solar-svn] Revision 2794
pmjones at solarphp.com
pmjones at solarphp.com
Fri Sep 28 20:46:26 CDT 2007
branch: Solar_Filter_ValidateCompare: [NEW] Compares one chain-element value to another for equality.
Modified: branches/orm/Solar/Filter/Locale/en_US.php
===================================================================
--- branches/orm/Solar/Filter/Locale/en_US.php 2007-09-29 01:45:32 UTC (rev 2793)
+++ branches/orm/Solar/Filter/Locale/en_US.php 2007-09-29 01:46:26 UTC (rev 2794)
@@ -19,6 +19,7 @@
'VALIDATE_ALPHA' => 'Please use only the letters A-Z.',
'VALIDATE_BLANK' => 'This value must be blank.',
'VALIDATE_BOOL' => 'This value should be true (yes) or false (no).',
+ 'VALIDATE_COMPARE' => 'This value is not the same as the other one.',
'VALIDATE_CTYPE' => 'This value does not match the required c-type.',
'VALIDATE_EMAIL' => 'Please enter a valid email address.',
'VALIDATE_FLOAT' => 'Please enter a floating-point number.',
Added: branches/orm/Solar/Filter/ValidateCompare.php
===================================================================
--- branches/orm/Solar/Filter/ValidateCompare.php (rev 0)
+++ branches/orm/Solar/Filter/ValidateCompare.php 2007-09-29 01:46:26 UTC (rev 2794)
@@ -0,0 +1,45 @@
+<?php
+class Solar_Filter_ValidateCompare extends Solar_Filter_Abstract {
+
+ /**
+ *
+ * Validates that this value is the same as some other value in the
+ * data filter chain.
+ *
+ * When this value is exactly null, the comparison is not performed.
+ * Empty string, numeric zero, and boolean false will all enable the
+ * comparison check.
+ *
+ * Useful for checking that the user entered the same password twice, or
+ * the same email twice, etc.
+ *
+ * Be sure to use this only as part of a filter chain, as it will attempt
+ * to look up the other value in the filter data.
+ *
+ * @param mixed $value The value to validate. If exactly null, the
+ * validation will automatically pass.
+ *
+ * @param string $compare_key Check against the value of this element in
+ * $this->_data.
+ *
+ * @param bool $strict When true, does a type comparison in addition to
+ * a value comparison (i.e., `===` and not just `==`).
+ *
+ * @return bool True if the values are the same, false if not.
+ *
+ */
+ public function validateCompare($value, $compare_key, $strict = false)
+ {
+ if ($value === null) {
+ return true;
+ }
+
+ $compare_val = $this->_filter->getData($compare_key);
+
+ if ($strict) {
+ return $value === $compare_val;
+ } else {
+ return $value == $compare_val;
+ }
+ }
+}
More information about the Solar-svn
mailing list