cvs: php4 /pear PEAR.php
| From: | Jan Lehnardt | Date: | Wed, 29 May 2002 21:41:27 +0000 |
| Subject: | cvs: php4 /pear PEAR.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-4276@lists.php.net to get a copy of this message | ||
jan Wed May 29 17:41:27 2002 EDT
Modified files:
/php4/pear PEAR.php
Log:
- added delExpect() API method. It allows to unset one or more expected
- error codes.
- requires _checkDelExpect() (private) which I added as well.
- inspired by chregu (PHP-Deluxe, page 75)
Index: php4/pear/PEAR.php
diff -u php4/pear/PEAR.php:1.39 php4/pear/PEAR.php:1.40
--- php4/pear/PEAR.php:1.39 Sun May 26 08:50:36 2002
+++ php4/pear/PEAR.php Wed May 29 17:41:27 2002
@@ -18,7 +18,7 @@
// | Tomas V.V.Cox <cox@idecnet.com> |
// +----------------------------------------------------------------------+
//
-// $Id: PEAR.php,v 1.39 2002/05/26 12:50:36 ssb Exp $
+// $Id: PEAR.php,v 1.40 2002/05/29 21:41:27 jan Exp $
//
define('PEAR_ERROR_RETURN', 1);
@@ -345,6 +345,76 @@
function popExpect()
{
return array_pop($this->_expected_errors);
+ }
+
+ // }}}
+ // {{{ _checkDelExpect()
+
+ /**
+ * This method checks unsets an error code if available
+ *
+ * @param mixed error code
+ * @return bool true if the error code was unset, false otherwise
+ * @access private
+ * @since PHP 4.3.0
+ */
+ function _checkDelExpect($error_code)
+ {
+ $deleted = false;
+
+ foreach ($this->_expected_errors AS $key => $error_array) {
+ if (in_array($error_code, $error_array)) {
+ unset($this->_expected_errors[$key][array_search($error_code, $error_array)]);
+ $deleted = true;
+ }
+
+ // clean up empty arrays
+ if (0 == count($this->_expected_errors[$key])) {
+ unset($this->_expected_errors[$key]);
+ }
+ }
+ return $deleted;
+ }
+
+ // }}}
+ // {{{ delExpect()
+
+ /**
+ * This method deletes all occurences of the specified element from
+ * the expected error codes stack.
+ *
+ * @param mixed $error_code error code that should be deleted
+ * @return mixed list of error codes that were deleted or error
+ * @access public
+ * @since PHP 4.3.0
+ */
+ function delExpect($error_code)
+ {
+ $deleted = false;
+
+ if ((is_array($error_code) && (0 != count($error_code)))) {
+ // $error_code is a non-empty array here;
+ // we walk through it trying to unset all
+ // values
+ foreach($error_code AS $key => $error) {
+ if ($this->_checkDelExpect($error)) {
+ $deleted = true;
+ } else {
+ $deleted = false;
+ }
+ }
+ return $deleted?true:PEAR::raiseError("The expected error you submitted does not
exist"); // IMPROVE ME
+ } elseif (!empty($error_code)) {
+ // $error_code comes alone, trying to unset it
+ if ($this->_checkDelExpect($error_code)) {
+ return true;
+ } else {
+ return PEAR::raiseError("The expected error you submitted does not
exist"); // IMPROVE ME
+ }
+ } else {
+ // $error_code is empty
+ return PEAR::raiseError("The expected error you submitted is empty"); //
IMPROVE ME
+ }
}
// }}}