mirror of
https://github.com/php/php-src.git
synced 2026-04-17 13:01:02 +02:00
PEAR:
* show what's going on when PEAR files are installed * allow multiple modes (or'ed) in PEAR_Error @PEAR: allow multiple modes in PEAR_Error (Stig)
This commit is contained in:
@@ -41,15 +41,15 @@ PEAR_FILES = \
|
||||
install-data-local: PEAR.php
|
||||
@if $(mkinstalldirs) $(peardir); then \
|
||||
for i in $(PEAR_SUBDIRS); do \
|
||||
$(mkinstalldirs) $(peardir)/$$i; \
|
||||
(set -x;$(mkinstalldirs) $(peardir)/$$i); \
|
||||
done; \
|
||||
for i in $(PEAR_FILES); do \
|
||||
dir=`echo $$i|sed 's%[^/][^/]*$$%%'`; \
|
||||
$(INSTALL_DATA) $(srcdir)/$$i $(peardir)/$$dir; \
|
||||
(set -x;$(INSTALL_DATA) $(srcdir)/$$i $(peardir)/$$dir); \
|
||||
done; \
|
||||
for i in PEAR.php; do \
|
||||
dir=`echo $$i|sed 's%[^/][^/]*$$%%'`; \
|
||||
$(INSTALL_DATA) $(builddir)/$$i $(peardir)/$$dir; \
|
||||
(set -x;$(INSTALL_DATA) $(builddir)/$$i $(peardir)/$$dir); \
|
||||
done; \
|
||||
else \
|
||||
cat $(srcdir)/install-pear.txt; \
|
||||
|
||||
115
pear/PEAR.php.in
115
pear/PEAR.php.in
@@ -20,11 +20,11 @@
|
||||
// $Id$
|
||||
//
|
||||
|
||||
define('PEAR_ERROR_RETURN', 0);
|
||||
define('PEAR_ERROR_PRINT', 1);
|
||||
define('PEAR_ERROR_TRIGGER', 2);
|
||||
define('PEAR_ERROR_DIE', 3);
|
||||
define('PEAR_ERROR_CALLBACK', 4);
|
||||
define('PEAR_ERROR_RETURN', 1);
|
||||
define('PEAR_ERROR_PRINT', 2);
|
||||
define('PEAR_ERROR_TRIGGER', 4);
|
||||
define('PEAR_ERROR_DIE', 8);
|
||||
define('PEAR_ERROR_CALLBACK', 16);
|
||||
|
||||
define('PHP_BINDIR', '@prefix@/bin');
|
||||
define('PEAR_INSTALL_DIR', '@PEAR_INSTALLDIR@');
|
||||
@@ -177,44 +177,45 @@ class PEAR_Error
|
||||
*/
|
||||
function PEAR_Error($message = 'unknown error',
|
||||
$code = 0,
|
||||
$mode = PEAR_ERROR_RETURN,
|
||||
$level = E_USER_NOTICE)
|
||||
$mode = null,
|
||||
$options = null)
|
||||
{
|
||||
if ($mode === null) {
|
||||
$mode = PEAR_ERROR_RETURN;
|
||||
}
|
||||
$this->message = $message;
|
||||
$this->code = $code;
|
||||
$this->mode = $mode;
|
||||
if ($mode == PEAR_ERROR_CALLBACK) {
|
||||
if ($mode & PEAR_ERROR_CALLBACK) {
|
||||
$this->level = E_USER_NOTICE;
|
||||
$this->callback = $level;
|
||||
$this->callback = $options;
|
||||
} else {
|
||||
$this->level = $level;
|
||||
$this->callback = false;
|
||||
if ($options === null) {
|
||||
$options = E_USER_NOTICE;
|
||||
}
|
||||
$this->level = $options;
|
||||
$this->callback = null;
|
||||
}
|
||||
switch ($this->mode) {
|
||||
case PEAR_ERROR_PRINT:
|
||||
print $this->getMessage();
|
||||
break;
|
||||
case PEAR_ERROR_TRIGGER:
|
||||
trigger_error($this->getMessage(), $this->level);
|
||||
break;
|
||||
case PEAR_ERROR_DIE:
|
||||
die($this->getMessage());
|
||||
break;
|
||||
case PEAR_ERROR_CALLBACK:
|
||||
if (is_string($this->callback) && strlen($this->callback)) {
|
||||
call_user_func($this->callback, $this);
|
||||
} elseif (is_array($this->callback) &&
|
||||
sizeof($this->callback) == 2 &&
|
||||
is_object($this->callback[0]) &&
|
||||
is_string($this->callback[1]) &&
|
||||
strlen($this->callback[1])) {
|
||||
call_user_method($this->callback[1], $this->callback[0],
|
||||
$this);
|
||||
}
|
||||
break;
|
||||
case PEAR_ERROR_RETURN:
|
||||
default:
|
||||
break;
|
||||
if ($this->mode & PEAR_ERROR_PRINT) {
|
||||
print $this->getMessage();
|
||||
}
|
||||
if ($this->mode & PEAR_ERROR_TRIGGER) {
|
||||
trigger_error($this->getMessage(), $this->level);
|
||||
}
|
||||
if ($this->mode & PEAR_ERROR_DIE) {
|
||||
die($this->getMessage());
|
||||
}
|
||||
if ($this->mode & PEAR_ERROR_CALLBACK) {
|
||||
if (is_string($this->callback) && strlen($this->callback)) {
|
||||
call_user_func($this->callback, $this);
|
||||
} elseif (is_array($this->callback) &&
|
||||
sizeof($this->callback) == 2 &&
|
||||
is_object($this->callback[0]) &&
|
||||
is_string($this->callback[1]) &&
|
||||
strlen($this->callback[1])) {
|
||||
call_user_method($this->callback[1], $this->callback[0],
|
||||
$this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,19 +284,43 @@ class PEAR_Error
|
||||
* @return string a string with an object "summary"
|
||||
*/
|
||||
function toString() {
|
||||
$modes = array(PEAR_ERROR_RETURN => "return",
|
||||
PEAR_ERROR_PRINT => "print",
|
||||
PEAR_ERROR_TRIGGER => "trigger",
|
||||
PEAR_ERROR_DIE => "die",
|
||||
PEAR_ERROR_CALLBACK => "callback");
|
||||
$modes = array();
|
||||
$levels = array(E_USER_NOTICE => "notice",
|
||||
E_USER_WARNING => "warning",
|
||||
E_USER_ERROR => "error");
|
||||
return sprintf("[%s: message=\"%s\" code=%d mode=%s level=%s prefix=\"%s\" prepend=\"%s\" append=\"%s\"]",
|
||||
if ($this->mode & PEAR_ERROR_CALLBACK) {
|
||||
if (is_array($this->callback)) {
|
||||
$callback = get_class($this->callback[0]) . "::" .
|
||||
$this->callback[1];
|
||||
} else {
|
||||
$callback = $this->callback;
|
||||
}
|
||||
return sprintf('[%s: message="%s" code=%d mode=callback '.
|
||||
'callback=%s prefix="%s" prepend="%s" append="%s"]',
|
||||
get_class($this), $this->message, $this->code,
|
||||
$callback, $this->error_message_prefix,
|
||||
$this->error_prepend, $this->error_append);
|
||||
}
|
||||
if ($this->mode & PEAR_ERROR_CALLBACK) {
|
||||
$modes[] = "callback";
|
||||
}
|
||||
if ($this->mode & PEAR_ERROR_PRINT) {
|
||||
$modes[] = "print";
|
||||
}
|
||||
if ($this->mode & PEAR_ERROR_TRIGGER) {
|
||||
$modes[] = "trigger";
|
||||
}
|
||||
if ($this->mode & PEAR_ERROR_DIE) {
|
||||
$modes[] = "die";
|
||||
}
|
||||
if ($this->mode & PEAR_ERROR_RETURN) {
|
||||
$modes[] = "return";
|
||||
}
|
||||
return sprintf('[%s: message="%s" code=%d mode=%s level=%s prefix="%s" prepend="%s" append="%s"]',
|
||||
get_class($this), $this->message, $this->code,
|
||||
$modes[$this->mode], $levels[$this->level],
|
||||
$this->error_message_prefix, $this->error_prepend,
|
||||
$this->error_append);
|
||||
implode("|", $modes), $levels[$this->level],
|
||||
$this->error_message_prefix,
|
||||
$this->error_prepend, $this->error_append);
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
@@ -13,6 +13,18 @@ require_once "PEAR.php";
|
||||
|
||||
error_reporting(4095);
|
||||
|
||||
function errorhandler(&$obj) {
|
||||
print "errorhandler function called, obj=".$obj->toString()."\n";
|
||||
}
|
||||
|
||||
class errorclass {
|
||||
function errorhandler(&$obj) {
|
||||
print "errorhandler method called, obj=".$obj->toString()."\n";
|
||||
}
|
||||
}
|
||||
|
||||
$eo = new errorclass;
|
||||
|
||||
print "default PEAR_Error: ";
|
||||
$err = new PEAR_Error;
|
||||
print $err->toString() . "\n";
|
||||
@@ -23,24 +35,42 @@ $str = "not an error";
|
||||
var_dump(PEAR::isError($str));
|
||||
|
||||
print "Now trying a bunch of variations...\n";
|
||||
|
||||
print "different message: ";
|
||||
$err = new PEAR_Error("test error");
|
||||
print $err->toString() . "\n";
|
||||
|
||||
print "different message,code: ";
|
||||
$err = new PEAR_Error("test error", -42);
|
||||
print $err->toString() . "\n";
|
||||
|
||||
print "mode=print: ";
|
||||
$err = new PEAR_Error("test error", -42, PEAR_ERROR_PRINT);
|
||||
print $err->toString() . "\n";
|
||||
|
||||
print "mode=callback(function): ";
|
||||
$err = new PEAR_Error("test error", -42, PEAR_ERROR_CALLBACK, "errorhandler");
|
||||
|
||||
print "mode=callback(method): ";
|
||||
$err = new PEAR_Error("test error", -42, PEAR_ERROR_CALLBACK,
|
||||
array(&$eo, "errorhandler"));
|
||||
|
||||
print "mode=print&trigger: ";
|
||||
$err = new PEAR_Error("test error", -42, PEAR_ERROR_PRINT|PEAR_ERROR_TRIGGER);
|
||||
print $err->toString() . "\n";
|
||||
|
||||
print "mode=trigger: ";
|
||||
$err = new PEAR_Error("test error", -42, PEAR_ERROR_TRIGGER);
|
||||
print $err->toString() . "\n";
|
||||
|
||||
print "mode=trigger,level=notice: ";
|
||||
$err = new PEAR_Error("test error", -42, PEAR_ERROR_TRIGGER, E_USER_NOTICE);
|
||||
print $err->toString() . "\n";
|
||||
|
||||
print "mode=trigger,level=warning: ";
|
||||
$err = new PEAR_Error("test error", -42, PEAR_ERROR_TRIGGER, E_USER_WARNING);
|
||||
print $err->toString() . "\n";
|
||||
|
||||
print "mode=trigger,level=error: ";
|
||||
$err = new PEAR_Error("test error", -42, PEAR_ERROR_TRIGGER, E_USER_ERROR);
|
||||
print $err->toString() . "\n";
|
||||
@@ -56,14 +86,19 @@ Now trying a bunch of variations...
|
||||
different message: [pear_error: message="test error" code=0 mode=return level=notice prefix="" prepend="" append=""]
|
||||
different message,code: [pear_error: message="test error" code=-42 mode=return level=notice prefix="" prepend="" append=""]
|
||||
mode=print: test error[pear_error: message="test error" code=-42 mode=print level=notice prefix="" prepend="" append=""]
|
||||
mode=callback(function): errorhandler function called, obj=[pear_error: message="test error" code=-42 mode=callback callback=errorhandler prefix="" prepend="" append=""]
|
||||
mode=callback(method): errorhandler method called, obj=[pear_error: message="test error" code=-42 mode=callback callback=errorclass::errorhandler prefix="" prepend="" append=""]
|
||||
mode=print&trigger: test error<br>
|
||||
<b>Notice</b>: test error in <b>PEAR.php</b> on line <b>203</b><br>
|
||||
[pear_error: message="test error" code=-42 mode=print|trigger level=notice prefix="" prepend="" append=""]
|
||||
mode=trigger: <br>
|
||||
<b>Notice</b>: test error in <b>PEAR.php</b> on line <b>198</b><br>
|
||||
<b>Notice</b>: test error in <b>PEAR.php</b> on line <b>203</b><br>
|
||||
[pear_error: message="test error" code=-42 mode=trigger level=notice prefix="" prepend="" append=""]
|
||||
mode=trigger,level=notice: <br>
|
||||
<b>Notice</b>: test error in <b>PEAR.php</b> on line <b>198</b><br>
|
||||
<b>Notice</b>: test error in <b>PEAR.php</b> on line <b>203</b><br>
|
||||
[pear_error: message="test error" code=-42 mode=trigger level=notice prefix="" prepend="" append=""]
|
||||
mode=trigger,level=warning: <br>
|
||||
<b>Warning</b>: test error in <b>PEAR.php</b> on line <b>198</b><br>
|
||||
<b>Warning</b>: test error in <b>PEAR.php</b> on line <b>203</b><br>
|
||||
[pear_error: message="test error" code=-42 mode=trigger level=warning prefix="" prepend="" append=""]
|
||||
mode=trigger,level=error: <br>
|
||||
<b>Fatal error</b>: test error in <b>PEAR.php</b> on line <b>198</b><br>
|
||||
<b>Fatal error</b>: test error in <b>PEAR.php</b> on line <b>203</b><br>
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
--TEST--
|
||||
PEAR_Error in callback mode
|
||||
--SKIPIF--
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require_once "PEAR.php";
|
||||
|
||||
function error_function($obj) {
|
||||
print "this is error_function reporting: ";
|
||||
print $obj->toString();
|
||||
print "\n";
|
||||
}
|
||||
class myclass {
|
||||
function error_method($obj) {
|
||||
print "this is myclass::error_method reporting: ";
|
||||
print $obj->toString();
|
||||
print "\n";
|
||||
}
|
||||
}
|
||||
$obj = new myclass;
|
||||
new PEAR_Error("errortest1", 0, PEAR_ERROR_CALLBACK, "error_function");
|
||||
new PEAR_Error("errortest2", 0, PEAR_ERROR_CALLBACK,
|
||||
array(&$obj, "error_method"));
|
||||
|
||||
|
||||
?>
|
||||
--GET--
|
||||
--POST--
|
||||
--EXPECT--
|
||||
this is error_function reporting: [pear_error: message="errortest1" code=0 mode=callback level=notice prefix="" prepend="" append=""]
|
||||
this is myclass::error_method reporting: [pear_error: message="errortest2" code=0 mode=callback level=notice prefix="" prepend="" append=""]
|
||||
Reference in New Issue
Block a user