[limb-svn] r6639 - in 3.x/trunk/limb/validation: src src/exception tests/cases
svn at limb-project.com
svn at limb-project.com
Tue Dec 25 12:01:29 MSK 2007
Author: serega
Date: 2007-12-25 12:01:29 +0300 (Tue, 25 Dec 2007)
New Revision: 6639
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6639
Modified:
3.x/trunk/limb/validation/src/exception/lmbValidationException.class.php
3.x/trunk/limb/validation/src/lmbErrorList.class.php
3.x/trunk/limb/validation/tests/cases/lmbErrorListTest.class.php
Log:
-- lmbErrorList :: setFieldNameDictionary(), getFieldName() methods removed.
-- lmbErrorList uses ArrayAccess interface for getting errors fields. Errors now are simple arrays not lmbObject objects.
Modified: 3.x/trunk/limb/validation/src/exception/lmbValidationException.class.php
===================================================================
--- 3.x/trunk/limb/validation/src/exception/lmbValidationException.class.php 2007-12-25 08:58:50 UTC (rev 6638)
+++ 3.x/trunk/limb/validation/src/exception/lmbValidationException.class.php 2007-12-25 09:01:29 UTC (rev 6639)
@@ -33,12 +33,8 @@
{
$this->error_list = $error_list->getReadable();
- $errors = array();
- foreach($this->error_list as $error)
- $errors[] .= $error->getMessage();
+ $message .= ' Errors list : ' . implode(', ', $this->error_list);
- $message .= ' Errors list : ' . implode(', ', $errors);
-
parent :: __construct($message, $params, $code);
}
Modified: 3.x/trunk/limb/validation/src/lmbErrorList.class.php
===================================================================
--- 3.x/trunk/limb/validation/src/lmbErrorList.class.php 2007-12-25 08:58:50 UTC (rev 6638)
+++ 3.x/trunk/limb/validation/src/lmbErrorList.class.php 2007-12-25 09:01:29 UTC (rev 6639)
@@ -7,7 +7,6 @@
* @license LGPL http://www.gnu.org/copyleft/lesser.html
*/
lmb_require('limb/core/src/lmbCollection.class.php');
-lmb_require('limb/core/src/lmbObject.class.php');
/**
* Holds a list of validation errors
@@ -18,35 +17,16 @@
class lmbErrorList extends lmbCollection
{
/**
- * @see lmbErrorMessage :: getErrorMessage()
- * @see getFieldName()
- * @var object Field name dictionary that is used in making human readable error messages
- */
- protected $field_name_dictionary;
-
- /**
- * Sets new field name dictionary
- * Usually this happens in {@link WactFormComponent :: setErrors()}
- * @see WactFormFieldNameDictionary
- * @param mixed New field name dictionary object.
- * @return void
- */
- function setFieldNameDictionary($dictionary)
- {
- $this->field_name_dictionary = $dictionary;
- }
-
- /**
* Adds new error.
* Creates an object of {@link lmbErrorMessage} class.
* Accepts error message, array of fields list which this error is belong to and array of values.
* Error message can contain placeholders like {Placeholder} that will be replaced with field names
- * and values in {@link lmbErrorMessage :: getReadableErrorList()}
+ * and values in {@link lmbErrorMessage :: getReadable()}
* Here is an example of adding error to error list in some validation rule:
* <code>
* $error_list->addError('{Field} must contain at least {min} characters.', array('Field' => 'password'), array('min' => 5));
* </code>
- * After all replacements we can get something like "Password must contain at least 5 characters", there "password" becomes "Password"
+ * After all replacements we can get something like "password must contain at least 5 characters"
* @param string Error message with placeholders like {Field} must contain at least {min} characters.
* @param array Array of aliases and field names like array('BaseField' => 'password', 'RepeatField' => 'repeat_password')
* @param array Array of aliases and field values like array('Min' => 5, 'Max' => 15)
@@ -54,29 +34,12 @@
*/
function addError($message, $fields = array(), $values = array())
{
- $error = new lmbObject(array('message' => $message,
- 'error' => $message, // for BC
- 'fields' => $fields,
- 'values' => $values));
+ $error = array('message' => $message, 'fields' => $fields, 'values' => $values);
$this->add($error);
return $error;
}
/**
- * Returns humal readable name of a field
- * Actually delegates to field name dictionary
- * @param string
- * @return string
- */
- function getFieldName($field)
- {
- if(is_object($this->field_name_dictionary))
- return $this->field_name_dictionary->getFieldName($field);
- else
- return $field;
- }
-
- /**
* Returns FALSE is contains at least one error, otherwise returns TRUE
* @return boolean
*/
@@ -86,30 +49,30 @@
}
/**
- * Return processed error list with translated and formatted messages
+ * Return processed error list with formatted messages
* @see lmbErrorList :: addError()
* @see __construct
* @return string
*/
function getReadable()
{
- $new_list = new lmbErrorList();
+ $result = array();
foreach($this as $error)
{
- $text = $error->getMessage();
+ $text = $error['message'];
- foreach($error->getFields() as $key => $fieldName)
+ foreach($error['fields'] as $key => $fieldName)
{
- $replacement = '"' . $this->getFieldName($fieldName) . '"';
+ $replacement = '"' . $fieldName . '"';
$text = str_replace('{' . $key . '}', $replacement, $text);
}
- foreach($error->getValues() as $key => $replacement)
+ foreach($error['values'] as $key => $replacement)
$text = str_replace('{' . $key . '}', $replacement, $text);
- $new_list->addError($text, $error->getFields(), $error->getValues());
+ $result[] = $text;
}
- return $new_list;
+ return $result;
}
}
Modified: 3.x/trunk/limb/validation/tests/cases/lmbErrorListTest.class.php
===================================================================
--- 3.x/trunk/limb/validation/tests/cases/lmbErrorListTest.class.php 2007-12-25 08:58:50 UTC (rev 6638)
+++ 3.x/trunk/limb/validation/tests/cases/lmbErrorListTest.class.php 2007-12-25 09:01:29 UTC (rev 6639)
@@ -22,9 +22,9 @@
$errors = $list->export();
$this->assertEqual(sizeof($errors), 1);
- $this->assertEqual($errors[0]->getMessage(), $message);
- $this->assertEqual($errors[0]->getFields(), array('foo'));
- $this->assertEqual($errors[0]->getValues(), array('FOO'));
+ $this->assertEqual($errors[0]['message'], $message);
+ $this->assertEqual($errors[0]['fields'], array('foo'));
+ $this->assertEqual($errors[0]['values'], array('FOO'));
}
}
More information about the limb-svn
mailing list