Changeset 21494 for branches/version-2_12-dev/data/module/PEAR.php
- Timestamp:
- 2012/02/13 15:49:08 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_12-dev/data/module/PEAR.php
r20116 r21494 7 7 * PHP versions 4 and 5 8 8 * 9 * LICENSE: This source file is subject to version 3.0 of the PHP license10 * that is available through the world-wide-web at the following URI:11 * http://www.php.net/license/3_0.txt. If you did not receive a copy of12 * the PHP License and are unable to obtain it through the web, please13 * send a note to license@php.net so we can mail you a copy immediately.14 *15 9 * @category pear 16 10 * @package PEAR … … 19 13 * @author Tomas V.V.Cox <cox@idecnet.com> 20 14 * @author Greg Beaver <cellog@php.net> 21 * @copyright 1997-20 06 The PHP Group22 * @license http:// www.php.net/license/3_0.txt PHP License 3.023 * @version CVS: $Id$15 * @copyright 1997-2010 The Authors 16 * @license http://opensource.org/licenses/bsd-license.php New BSD License 17 * @version CVS: commit 01071ee7b71e4d38c4e96fdf0ae5e411841eaec7 24 18 * @link http://pear.php.net/package/PEAR 25 19 * @since File available since Release 0.1 … … 51 45 define('OS_UNIX', true); 52 46 define('PEAR_OS', 'Unix'); // blatant assumption 53 }54 55 // instant backwards compatibility56 if (!defined('PATH_SEPARATOR')) {57 if (OS_WINDOWS) {58 define('PATH_SEPARATOR', ';');59 } else {60 define('PATH_SEPARATOR', ':');61 }62 47 } 63 48 … … 93 78 * @author Greg Beaver <cellog@php.net> 94 79 * @copyright 1997-2006 The PHP Group 95 * @license http:// www.php.net/license/3_0.txt PHP License 3.096 * @version Release: 1.4.680 * @license http://opensource.org/licenses/bsd-license.php New BSD License 81 * @version Release: @package_version@ 97 82 * @link http://pear.php.net/package/PEAR 98 83 * @see PEAR_Error … … 102 87 class PEAR 103 88 { 104 // {{{ properties105 106 89 /** 107 90 * Whether to enable internal debug messages. … … 153 136 */ 154 137 var $_expected_errors = array(); 155 156 // }}}157 158 // {{{ constructor159 138 160 139 /** … … 174 153 print "PEAR constructor called, class=$classname\n"; 175 154 } 155 176 156 if ($error_class !== null) { 177 157 $this->_error_class = $error_class; 178 158 } 159 179 160 while ($classname && strcasecmp($classname, "pear")) { 180 161 $destructor = "_$classname"; … … 193 174 } 194 175 195 // }}}196 // {{{ destructor197 198 176 /** 199 177 * Destructor (the emulated type of...). Does nothing right now, … … 212 190 } 213 191 } 214 215 // }}}216 // {{{ getStaticProperty()217 192 218 193 /** … … 231 206 { 232 207 static $properties; 208 if (!isset($properties[$class])) { 209 $properties[$class] = array(); 210 } 211 212 if (!array_key_exists($var, $properties[$class])) { 213 $properties[$class][$var] = null; 214 } 215 233 216 return $properties[$class][$var]; 234 217 } 235 236 // }}}237 // {{{ registerShutdownFunc()238 218 239 219 /** … … 248 228 function registerShutdownFunc($func, $args = array()) 249 229 { 230 // if we are called statically, there is a potential 231 // that no shutdown func is registered. Bug #6445 232 if (!isset($GLOBALS['_PEAR_SHUTDOWN_REGISTERED'])) { 233 register_shutdown_function("_PEAR_call_destructors"); 234 $GLOBALS['_PEAR_SHUTDOWN_REGISTERED'] = true; 235 } 250 236 $GLOBALS['_PEAR_shutdown_funcs'][] = array($func, $args); 251 237 } 252 253 // }}}254 // {{{ isError()255 238 256 239 /** … … 267 250 function isError($data, $code = null) 268 251 { 269 if (is_a($data, 'PEAR_Error')) { 270 if (is_null($code)) { 271 return true; 272 } elseif (is_string($code)) { 273 return $data->getMessage() == $code; 274 } else { 275 return $data->getCode() == $code; 276 } 277 } 278 return false; 279 } 280 281 // }}} 282 // {{{ setErrorHandling() 252 if (!is_object($data)) { 253 return false; 254 } 255 if (!is_a($data, 'PEAR_Error')) { 256 return false; 257 } 258 259 if (is_null($code)) { 260 return true; 261 } elseif (is_string($code)) { 262 return $data->getMessage() == $code; 263 } 264 265 return $data->getCode() == $code; 266 } 283 267 284 268 /** … … 320 304 * @since PHP 4.0.5 321 305 */ 322 323 306 function setErrorHandling($mode = null, $options = null) 324 307 { … … 358 341 } 359 342 360 // }}}361 // {{{ expectError()362 363 343 /** 364 344 * This method is used to tell which errors you expect to get. … … 383 363 array_push($this->_expected_errors, array($code)); 384 364 } 385 return sizeof($this->_expected_errors); 386 } 387 388 // }}} 389 // {{{ popExpect() 365 return count($this->_expected_errors); 366 } 390 367 391 368 /** … … 399 376 return array_pop($this->_expected_errors); 400 377 } 401 402 // }}}403 // {{{ _checkDelExpect()404 378 405 379 /** … … 414 388 { 415 389 $deleted = false; 416 417 foreach ($this->_expected_errors AS $key => $error_array) { 390 foreach ($this->_expected_errors as $key => $error_array) { 418 391 if (in_array($error_code, $error_array)) { 419 392 unset($this->_expected_errors[$key][array_search($error_code, $error_array)]); … … 426 399 } 427 400 } 401 428 402 return $deleted; 429 403 } 430 431 // }}}432 // {{{ delExpect()433 404 434 405 /** … … 444 415 { 445 416 $deleted = false; 446 447 417 if ((is_array($error_code) && (0 != count($error_code)))) { 448 // $error_code is a non-empty array here; 449 // we walk through it trying to unset all 450 // values 451 foreach($error_code as $key => $error) { 452 if ($this->_checkDelExpect($error)) { 453 $deleted = true; 454 } else { 455 $deleted = false; 456 } 457 } 418 // $error_code is a non-empty array here; we walk through it trying 419 // to unset all values 420 foreach ($error_code as $key => $error) { 421 $deleted = $this->_checkDelExpect($error) ? true : false; 422 } 423 458 424 return $deleted ? true : PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME 459 425 } elseif (!empty($error_code)) { … … 461 427 if ($this->_checkDelExpect($error_code)) { 462 428 return true; 463 } else { 464 return PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME 465 } 466 } else { 467 // $error_code is empty 468 return PEAR::raiseError("The expected error you submitted is empty"); // IMPROVE ME 469 } 470 } 471 472 // }}} 473 // {{{ raiseError() 429 } 430 431 return PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME 432 } 433 434 // $error_code is empty 435 return PEAR::raiseError("The expected error you submitted is empty"); // IMPROVE ME 436 } 474 437 475 438 /** … … 525 488 $message->error_message_prefix = ''; 526 489 $message = $message->getMessage(); 527 } 528 529 if (isset($this) && isset($this->_expected_errors) && sizeof($this->_expected_errors) > 0 && sizeof($exp = end($this->_expected_errors))) { 490 491 // Make sure right data gets passed. 492 $r = new ReflectionClass($error_class); 493 $c = $r->getConstructor(); 494 $p = array_shift($c->getParameters()); 495 $skipmsg = ($p->getName() != 'message'); 496 } 497 498 if ( 499 isset($this) && 500 isset($this->_expected_errors) && 501 count($this->_expected_errors) > 0 && 502 count($exp = end($this->_expected_errors)) 503 ) { 530 504 if ($exp[0] == "*" || 531 505 (is_int(reset($exp)) && in_array($code, $exp)) || 532 (is_string(reset($exp)) && in_array($message, $exp))) { 506 (is_string(reset($exp)) && in_array($message, $exp)) 507 ) { 533 508 $mode = PEAR_ERROR_RETURN; 534 509 } 535 510 } 511 536 512 // No mode given, try global ones 537 513 if ($mode === null) { … … 554 530 $ec = 'PEAR_Error'; 555 531 } 532 533 if (intval(PHP_VERSION) < 5) { 534 // little non-eval hack to fix bug #12147 535 include 'PEAR/FixPHP5PEARWarnings.php'; 536 return $a; 537 } 538 556 539 if ($skipmsg) { 557 $a = &new $ec($code, $mode, $options, $userinfo); 558 return $a; 559 } else { 560 $a = &new $ec($message, $code, $mode, $options, $userinfo); 561 return $a; 562 } 563 } 564 565 // }}} 566 // {{{ throwError() 540 $a = new $ec($code, $mode, $options, $userinfo); 541 } else { 542 $a = new $ec($message, $code, $mode, $options, $userinfo); 543 } 544 545 return $a; 546 } 567 547 568 548 /** … … 570 550 * message, code and userinfo are enough. 571 551 * 572 * @param string $message 573 * 574 */ 575 function &throwError($message = null, 576 $code = null, 577 $userinfo = null) 552 * @param mixed $message a text error message or a PEAR error object 553 * 554 * @param int $code a numeric error code (it is up to your class 555 * to define these if you want to use codes) 556 * 557 * @param string $userinfo If you need to pass along for example debug 558 * information, this parameter is meant for that. 559 * 560 * @access public 561 * @return object a PEAR error object 562 * @see PEAR::raiseError 563 */ 564 function &throwError($message = null, $code = null, $userinfo = null) 578 565 { 579 566 if (isset($this) && is_a($this, 'PEAR')) { 580 567 $a = &$this->raiseError($message, $code, null, null, $userinfo); 581 568 return $a; 582 } else { 583 $a = &PEAR::raiseError($message, $code, null, null, $userinfo); 584 return $a; 585 } 586 } 587 588 // }}} 569 } 570 571 $a = &PEAR::raiseError($message, $code, null, null, $userinfo); 572 return $a; 573 } 574 589 575 function staticPushErrorHandling($mode, $options = null) 590 576 { 591 $stack = &$GLOBALS['_PEAR_error_handler_stack'];577 $stack = &$GLOBALS['_PEAR_error_handler_stack']; 592 578 $def_mode = &$GLOBALS['_PEAR_default_error_mode']; 593 579 $def_options = &$GLOBALS['_PEAR_default_error_options']; … … 658 644 } 659 645 660 // {{{ pushErrorHandling()661 662 646 /** 663 647 * Push a new error handler on top of the error handler options stack. With this … … 692 676 return true; 693 677 } 694 695 // }}}696 // {{{ popErrorHandling()697 678 698 679 /** … … 717 698 } 718 699 719 // }}}720 // {{{ loadExtension()721 722 700 /** 723 701 * OS independant PHP extension load. Remember to take care … … 729 707 function loadExtension($ext) 730 708 { 731 if (!extension_loaded($ext)) { 732 // if either returns true dl() will produce a FATAL error, stop that 733 if ((ini_get('enable_dl') != 1) || (ini_get('safe_mode') == 1)) { 734 return false; 735 } 736 if (OS_WINDOWS) { 737 $suffix = '.dll'; 738 } elseif (PHP_OS == 'HP-UX') { 739 $suffix = '.sl'; 740 } elseif (PHP_OS == 'AIX') { 741 $suffix = '.a'; 742 } elseif (PHP_OS == 'OSX') { 743 $suffix = '.bundle'; 744 } else { 745 $suffix = '.so'; 746 } 747 return @dl('php_'.$ext.$suffix) || @dl($ext.$suffix); 748 } 749 return true; 750 } 751 752 // }}} 709 if (extension_loaded($ext)) { 710 return true; 711 } 712 713 // if either returns true dl() will produce a FATAL error, stop that 714 if ( 715 function_exists('dl') === false || 716 ini_get('enable_dl') != 1 || 717 ini_get('safe_mode') == 1 718 ) { 719 return false; 720 } 721 722 if (OS_WINDOWS) { 723 $suffix = '.dll'; 724 } elseif (PHP_OS == 'HP-UX') { 725 $suffix = '.sl'; 726 } elseif (PHP_OS == 'AIX') { 727 $suffix = '.a'; 728 } elseif (PHP_OS == 'OSX') { 729 $suffix = '.bundle'; 730 } else { 731 $suffix = '.so'; 732 } 733 734 return @dl('php_'.$ext.$suffix) || @dl($ext.$suffix); 735 } 753 736 } 754 737 755 // {{{ _PEAR_call_destructors() 738 if (PEAR_ZE2) { 739 include_once 'PEAR5.php'; 740 } 756 741 757 742 function _PEAR_call_destructors() … … 762 747 { 763 748 reset($_PEAR_destructor_object_list); 764 if (@PEAR::getStaticProperty('PEAR', 'destructlifo')) { 749 if (PEAR_ZE2) { 750 $destructLifoExists = PEAR5::getStaticProperty('PEAR', 'destructlifo'); 751 } else { 752 $destructLifoExists = PEAR::getStaticProperty('PEAR', 'destructlifo'); 753 } 754 755 if ($destructLifoExists) { 765 756 $_PEAR_destructor_object_list = array_reverse($_PEAR_destructor_object_list); 766 757 } 758 767 759 while (list($k, $objref) = each($_PEAR_destructor_object_list)) { 768 760 $classname = get_class($objref); … … 783 775 784 776 // Now call the shutdown functions 785 if (is_array($GLOBALS['_PEAR_shutdown_funcs']) AND !empty($GLOBALS['_PEAR_shutdown_funcs'])) { 777 if ( 778 isset($GLOBALS['_PEAR_shutdown_funcs']) && 779 is_array($GLOBALS['_PEAR_shutdown_funcs']) && 780 !empty($GLOBALS['_PEAR_shutdown_funcs']) 781 ) { 786 782 foreach ($GLOBALS['_PEAR_shutdown_funcs'] as $value) { 787 783 call_user_func_array($value[0], $value[1]); … … 790 786 } 791 787 792 // }}}793 788 /** 794 789 * Standard PEAR error class for PHP 4 … … 802 797 * @author Gregory Beaver <cellog@php.net> 803 798 * @copyright 1997-2006 The PHP Group 804 * @license http:// www.php.net/license/3_0.txt PHP License 3.0805 * @version Release: 1.4.6799 * @license http://opensource.org/licenses/bsd-license.php New BSD License 800 * @version Release: @package_version@ 806 801 * @link http://pear.php.net/manual/en/core.pear.pear-error.php 807 802 * @see PEAR::raiseError(), PEAR::throwError() … … 810 805 class PEAR_Error 811 806 { 812 // {{{ properties813 814 807 var $error_message_prefix = ''; 815 808 var $mode = PEAR_ERROR_RETURN; … … 820 813 var $backtrace = null; 821 814 822 // }}}823 // {{{ constructor824 825 815 /** 826 816 * PEAR_Error constructor … … 853 843 $this->mode = $mode; 854 844 $this->userinfo = $userinfo; 855 if (function_exists("debug_backtrace")) { 856 if (@!PEAR::getStaticProperty('PEAR_Error', 'skiptrace')) { 857 $this->backtrace = debug_backtrace(); 858 } 859 } 845 846 if (PEAR_ZE2) { 847 $skiptrace = PEAR5::getStaticProperty('PEAR_Error', 'skiptrace'); 848 } else { 849 $skiptrace = PEAR::getStaticProperty('PEAR_Error', 'skiptrace'); 850 } 851 852 if (!$skiptrace) { 853 $this->backtrace = debug_backtrace(); 854 if (isset($this->backtrace[0]) && isset($this->backtrace[0]['object'])) { 855 unset($this->backtrace[0]['object']); 856 } 857 } 858 860 859 if ($mode & PEAR_ERROR_CALLBACK) { 861 860 $this->level = E_USER_NOTICE; … … 865 864 $options = E_USER_NOTICE; 866 865 } 866 867 867 $this->level = $options; 868 868 $this->callback = null; 869 869 } 870 870 871 if ($this->mode & PEAR_ERROR_PRINT) { 871 872 if (is_null($options) || is_int($options)) { … … 874 875 $format = $options; 875 876 } 877 876 878 printf($format, $this->getMessage()); 877 879 } 880 878 881 if ($this->mode & PEAR_ERROR_TRIGGER) { 879 882 trigger_error($this->getMessage(), $this->level); 880 883 } 884 881 885 if ($this->mode & PEAR_ERROR_DIE) { 882 886 $msg = $this->getMessage(); … … 891 895 die(sprintf($format, $msg)); 892 896 } 893 if ($this->mode & PEAR_ERROR_CALLBACK) { 894 if (is_callable($this->callback)) {895 896 897 } 897 898 if ($this->mode & PEAR_ERROR_CALLBACK && is_callable($this->callback)) { 899 call_user_func($this->callback, $this); 900 } 901 898 902 if ($this->mode & PEAR_ERROR_EXCEPTION) { 899 903 trigger_error("PEAR_ERROR_EXCEPTION is obsolete, use class PEAR_Exception for exceptions", E_USER_WARNING); … … 902 906 } 903 907 904 // }}}905 // {{{ getMode()906 907 908 /** 908 909 * Get the error mode from an error object. … … 911 912 * @access public 912 913 */ 913 function getMode() { 914 function getMode() 915 { 914 916 return $this->mode; 915 917 } 916 918 917 // }}}918 // {{{ getCallback()919 920 919 /** 921 920 * Get the callback function/method from an error object. … … 924 923 * @access public 925 924 */ 926 function getCallback() { 925 function getCallback() 926 { 927 927 return $this->callback; 928 928 } 929 929 930 // }}}931 // {{{ getMessage()932 933 934 930 /** 935 931 * Get the error message from an error object. … … 942 938 return ($this->error_message_prefix . $this->message); 943 939 } 944 945 946 // }}}947 // {{{ getCode()948 940 949 941 /** … … 958 950 } 959 951 960 // }}}961 // {{{ getType()962 963 952 /** 964 953 * Get the name of this error/exception. … … 972 961 } 973 962 974 // }}}975 // {{{ getUserInfo()976 977 963 /** 978 964 * Get additional user-supplied information. … … 986 972 } 987 973 988 // }}}989 // {{{ getDebugInfo()990 991 974 /** 992 975 * Get additional debug information supplied by the application. … … 999 982 return $this->getUserInfo(); 1000 983 } 1001 1002 // }}}1003 // {{{ getBacktrace()1004 984 1005 985 /** … … 1022 1002 } 1023 1003 1024 // }}}1025 // {{{ addUserInfo()1026 1027 1004 function addUserInfo($info) 1028 1005 { … … 1034 1011 } 1035 1012 1036 // }}} 1037 // {{{ toString() 1013 function __toString() 1014 { 1015 return $this->getMessage(); 1016 } 1038 1017 1039 1018 /** … … 1043 1022 * @access public 1044 1023 */ 1045 function toString() { 1024 function toString() 1025 { 1046 1026 $modes = array(); 1047 1027 $levels = array(E_USER_NOTICE => 'notice', … … 1082 1062 $this->userinfo); 1083 1063 } 1084 1085 // }}}1086 1064 } 1087 1065 … … 1093 1071 * End: 1094 1072 */ 1095 ?>
Note: See TracChangeset
for help on using the changeset viewer.