[limb-svn] r6706 - in 3.x/trunk/limb: active_record/tests/cases validation/src validation/src/exception

svn at limb-project.com svn at limb-project.com
Fri Jan 18 18:58:27 MSK 2008


Author: alex433
Date: 2008-01-18 18:58:27 +0300 (Fri, 18 Jan 2008)
New Revision: 6706
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6706

Added:
   3.x/trunk/limb/validation/src/lmbErrorMessage.class.php
Modified:
   3.x/trunk/limb/active_record/tests/cases/lmbARValidationTest.class.php
   3.x/trunk/limb/validation/src/exception/lmbValidationException.class.php
   3.x/trunk/limb/validation/src/lmbErrorList.class.php
Log:
-- adding lmbErrorMessage class. lmbErrorMessage::getReadable() return human readable error message.
-- lmbErrorList::getReadable() mark as deprecated
-- lmbValidationException::getErrorList() return original error_list object
-- fix lmbARValidationTest.

Modified: 3.x/trunk/limb/active_record/tests/cases/lmbARValidationTest.class.php
===================================================================
--- 3.x/trunk/limb/active_record/tests/cases/lmbARValidationTest.class.php	2008-01-18 14:28:35 UTC (rev 6705)
+++ 3.x/trunk/limb/active_record/tests/cases/lmbARValidationTest.class.php	2008-01-18 15:58:27 UTC (rev 6706)
@@ -158,7 +158,7 @@
     }
     catch(lmbValidationException $e)
     {
-      $this->assertEqual($e->getErrorList(), array('foo'));
+      $this->assertEqual($e->getErrorList(), $error_list);
     }
 
     $this->assertEqual($this->db->count('test_one_table_object'), 0);
@@ -209,7 +209,7 @@
     }
     catch(lmbValidationException $e)
     {
-      $this->assertEqual($e->getErrorList(), array('foo'));
+      $this->assertEqual($e->getErrorList(), $error_list);
     }
 
     $record = $this->db->selectRecord('test_one_table_object');

Modified: 3.x/trunk/limb/validation/src/exception/lmbValidationException.class.php
===================================================================
--- 3.x/trunk/limb/validation/src/exception/lmbValidationException.class.php	2008-01-18 14:28:35 UTC (rev 6705)
+++ 3.x/trunk/limb/validation/src/exception/lmbValidationException.class.php	2008-01-18 15:58:27 UTC (rev 6706)
@@ -31,10 +31,14 @@
   */
   function __construct($message, $error_list, $params = array(), $code = 0)
   {
-    $this->error_list = $error_list->getReadable();
+    $this->error_list = $error_list;
 
-    $message .= ' Errors list : ' . implode(', ', $this->error_list);
+    $errors = array();
+    foreach ($this->error_list as $error)
+      $errors[] = $error->getReadable();
 
+    $message .= ' Errors list : ' . implode(', ', $errors);
+
     parent :: __construct($message, $params, $code);
   }
 
@@ -43,5 +47,3 @@
     return $this->error_list;
   }
 }
-
-

Modified: 3.x/trunk/limb/validation/src/lmbErrorList.class.php
===================================================================
--- 3.x/trunk/limb/validation/src/lmbErrorList.class.php	2008-01-18 14:28:35 UTC (rev 6705)
+++ 3.x/trunk/limb/validation/src/lmbErrorList.class.php	2008-01-18 15:58:27 UTC (rev 6706)
@@ -7,6 +7,7 @@
  * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
  */
 lmb_require('limb/core/src/lmbCollection.class.php');
+lmb_require('limb/validation/src/lmbErrorMessage.class.php');
 
 /**
  * Holds a list of validation errors
@@ -34,7 +35,7 @@
   */
   function addError($message, $fields = array(), $values = array())
   {
-    $error = array('message' => $message, 'fields' => $fields, 'values' => $values);
+    $error = new lmbErrorMessage($message, $fields, $values);
     $this->add($error);
     return $error;
   }
@@ -50,6 +51,7 @@
 
   /**
   * Return processed error list with formatted messages
+  * @deprecated
   * @see lmbErrorList :: addError()
   * @see __construct
   * @return string
@@ -57,22 +59,9 @@
   function getReadable()
   {
     $result = array();
+    foreach ($this as $error)
+      $result[] = $error->getReadable();
 
-    foreach($this as $error)
-    {
-      $text = $error['message'];
-
-      foreach($error['fields'] as $key => $fieldName)
-      {
-        $replacement = '"' . $fieldName . '"';
-        $text = str_replace('{' . $key . '}', $replacement, $text);
-      }
-
-      foreach($error['values'] as $key => $replacement)
-        $text = str_replace('{' . $key . '}', $replacement, $text);
-
-      $result[] = $text;
-    }
     return $result;
   }
 }

Added: 3.x/trunk/limb/validation/src/lmbErrorMessage.class.php
===================================================================
--- 3.x/trunk/limb/validation/src/lmbErrorMessage.class.php	                        (rev 0)
+++ 3.x/trunk/limb/validation/src/lmbErrorMessage.class.php	2008-01-18 15:58:27 UTC (rev 6706)
@@ -0,0 +1,43 @@
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com 
+ * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
+ * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
+ */
+lmb_require('limb/core/src/lmbCollection.class.php');
+lmb_require('limb/validation/src/lmbErrorMessage.class.php');
+
+/**
+ * Single validation error message.
+ * @package validation
+ * @version $Id$
+ */
+class lmbErrorMessage extends lmbObject  
+{  
+  function __construct($message, $fields = array(), $values = array())  
+  {  
+     parent::__construct(array('message' => $message, 'fields' => $fields, 'values' => $values));
+  }
+
+  function getReadable()  
+  {   
+    $text = $this->getMessage();
+    foreach($this->getFields() as $key => $fieldName)
+    {
+      $replacement = '"' . $fieldName . '"';
+      $text = str_replace('{' . $key . '}', $replacement, $text);
+    }
+
+    foreach($this->getValues() as $key => $replacement)
+      $text = str_replace('{' . $key . '}', $replacement, $text);
+
+    return $text;
+  }  
+
+  function __toString()
+  {
+      return $this->getReadable();
+  }
+}



More information about the limb-svn mailing list