Re: [Fwd: [PEAR-CVS] cvs: pear /MDB2 MDB2.php]

From: Date: Tue, 14 Mar 2006 12:53:59 +0000
Subject: Re: [Fwd: [PEAR-CVS] cvs: pear /MDB2 MDB2.php]
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-41781@lists.php.net to get a copy of this message
It makes sense to make the property public. No need to have wrappers methods and so on. Arnaud. Lukas Kahwe Smith wrote:
Hi, I just commited a simple solution to make it possible to overwrite the error code-message mapping in MDB2. I did a quick search on PEAR and alot of packages are using a similar implementation. In LiveUser I am pondering making the errorstack property public, since there is native support for error code-message customization through the setErrorMessageTemplate() method. Comments would be appreciated. regards, Lukas Modified files:
    /pear/MDB2    MDB2.php
Log: - make it possible to overwrite the error code-message map http://cvs.php.net/viewcvs.cgi/pear/MDB2/MDB2.php?r1=1.173&r2=1.174&diff_format=u Index: pear/MDB2/MDB2.php diff -u pear/MDB2/MDB2.php:1.173 pear/MDB2/MDB2.php:1.174
--- pear/MDB2/MDB2.php:1.173    Sat Mar 11 10:30:04 2006
+++ pear/MDB2/MDB2.php    Tue Mar 14 12:42:13 2006
@@ -43,7 +43,7 @@
 // | Author: Lukas Smith <smith@pooteeweet.org>     |
 // +----------------------------------------------------------------------+
// -// $Id: MDB2.php,v 1.173 2006/03/11 10:30:04 lsmith Exp $ +// $Id: MDB2.php,v 1.174 2006/03/14 12:42:13 lsmith Exp $ // /** @@ -611,16 +611,22 @@
     /**
      * Return a textual error message for a MDB2 error code
      *
-     * @param   int     $value error code
+     * @param   int|array $value integer error code,
+                                null to get the current error code-message map,
+                                or an array with a new error code-message map
      * @return  string  error message, or false if the error code was
      *                  not recognized
      * @access public
      */
-    function errorMessage($value)
+    function errorMessage($value = null)
     {
         static $errorMessages;
-        if (!isset($errorMessages)) {
+        if (is_array($value)) {
+            $errorMessages = $value;
+            return MDB2_OK;
+        } elseif (!isset($errorMessages)) {
             $errorMessages = array(
+                MDB2_OK                       => 'no error',
                 MDB2_ERROR                    => 'unknown error',
                 MDB2_ERROR_ALREADY_EXISTS     => 'already exists',
                 MDB2_ERROR_CANNOT_CREATE      => 'can not create',
@@ -646,7 +652,6 @@
                 MDB2_ERROR_VALUE_COUNT_ON_ROW => 'value count on row',
                 MDB2_ERROR_INVALID_DSN        => 'invalid DSN',
                 MDB2_ERROR_CONNECT_FAILED     => 'connect failed',
-                MDB2_OK                       => 'no error',
                 MDB2_ERROR_NEED_MORE_DATA     => 'insufficient data supplied',
                 MDB2_ERROR_EXTENSION_NOT_FOUND=> 'extension not found',
                 MDB2_ERROR_NOSUCHDB           => 'no such database',
@@ -657,6 +662,10 @@
             );
         }
+        if (is_null($value)) {
+            return $errorMessages;
+        }
+
         if (PEAR::isError($value)) {
             $value = $value->getCode();
         }


« previous php.pear.dev (#41781) next »