/** * Re-assign an error to this error's package * * If an error is returned that needs to be re-defined for another package, * this method should be called from the pre-existing error in order to * transform it into another package's error * @param string package name of new error object * @param error|warning|notice|exception error severity * @param integer error code * @param array|null|false any new information for the error message, * otherwise existing information will be used. If passed false, * the new information will be set to null * @throws ERROR_RAISE_ERROR_INVALID_INPUT */ function &rePackageError($package, $type, $code, $extrainfo = null) { if (!is_string($type)) { return Error_Raise::exception('error_raise', ERROR_RAISE_ERROR_INVALID_INPUT, array('was' => gettype($type), 'expected' => 'string', 'param' => '$type', 'paramnum' => 2)); } $type = strtolower($type); if (!in_array($type, array('error', 'warning', 'notice', 'exception'))) { return Error_Raise::exception('error_raise', ERROR_RAISE_ERROR_INVALID_INPUT, array('was' => $type, 'expected' => array('error', 'warning', 'notice', 'exception'), 'param' => '$type', 'paramnum' => 2)); } if (!is_string($package)) { return Error_Raise::exception('error_raise', ERROR_RAISE_ERROR_INVALID_INPUT, array('was' => gettype($package), 'expected' => 'string', 'param' => '$package', 'paramnum' => 1)); } if (!class_exists($errorclass = $package . '_error')) { $errorclass = 'error_raise_error'; } $backtrace = false; if (function_exists('debug_backtrace')) { $backtrace = debug_backtrace(); } $e = new $errorclass($package, $type, $code, $extrainfo, $this->mode, $this->callback, $backtrace, $this); return $e; }
/** * Temporarily disable any error callbacks/trigger_error. * * To temporarily disable callback functions in order to suppress any * error reporting of internal errors, use this static method. To * selectively disable a short list of packages, and allow others to inform * callbacks of their creation, pass in an array of the names of packages * to disable errors for. * * This is similar to PEAR::expectError(), except that only global * error-handling is affected * @param array list of packages to disable error callbacks for * @throws Error_Raise_Exception::ERROR_RAISE_ERROR_INVALID_INPUT * @return true|Error_Raise_Exception * @static */ function disableErrorCallbacks($packages = array()) { if (!is_array($packages) && !is_string($packages)) { return Error_Raise::exception('error_raise', ERROR_RAISE_ERROR_INVALID_INPUT, array('was' => gettype($packages), 'expected' => 'array|string', 'param' => '$packages', 'paramnum' => 1)); } if (is_string($packages)) { $packages = array($packages); } $newpack = array(); foreach ($packages as $i => $package) { if (!is_string($package)) { return Error_Raise::exception('error_raise', ERROR_RAISE_ERROR_INVALID_INPUT, array('was' => gettype($package), 'expected' => 'string', 'param' => '$packages[' . $i . ']', 'paramnum' => 1)); } $newpack[] = strtolower($package); } if (!count($newpack)) { array_push($GLOBALS['_ERROR_RAISE_DISABLED_CALLBACKS'], '*'); } else { array_push($GLOBALS['_ERROR_RAISE_DISABLED_CALLBACKS'], $newpack); } return true; }
/** * Verify that $callback is a valid function callback * * This is used to be absolutely sure a callback is valid before registering * it, to avoid later errors on the throwing of an error * @param string|array * @return true|Error_Raise_Error * @throws ERROR_UTIL_ERROR_FUNCTION_DOESNT_EXIST If the callback is a * string and isn't the name of any function * @throws ERROR_UTIL_ERROR_INTERNAL_FUNCTION If the callback is the name * of an internal, pre-defined function like "function_exists" * @throws ERROR_UTIL_ERROR_INVALID_INPUT If the callback is neither * a string, an array(classname, method), or an array(object, method) * @throws ERROR_UTIL_ERROR_METHOD_DOESNT_EXIST if the callback is an * array, and the method is not a method of the class * @access private */ function _validCallback($callback) { static $init = false; if (!$init) { $init = true; Error_Raise::setErrorMsgGenerator('Error_Util', array('Error_Util', 'genErrorMessage')); } if (is_string($callback)) { if (!function_exists($callback)) { return Error_Raise::exception('Error_Util', ERROR_UTIL_ERROR_FUNCTION_DOESNT_EXIST, array('function' => $callback)); } $a = get_defined_functions(); if (in_array($callback, $a['internal'])) { return Error_Raise::exception('Error_Util', ERROR_UTIL_ERROR_INTERNAL_FUNCTION, array('function' => $callback)); } return true; } if (is_array($callback)) { if (!isset($callback[0]) || !isset($callback[1])) { return Error_Raise::exception('Error_Util', ERROR_UTIL_ERROR_INVALID_INPUT, array('expected' => array(0, 1), 'was' => array_keys($callback), 'var' => 'array_keys($callback)', 'paramnum' => 1)); } if (is_string($callback[0])) { if (!is_string($callback[1])) { return Error_Raise::exception('Error_Util', ERROR_UTIL_ERROR_INVALID_INPUT, array('expected' => 'string', 'was' => gettype($callback[1]), 'var' => '$callback[1]', 'paramnum' => 1)); } if (!class_exists($callback[0])) { return Error_Raise::exception('Error_Util', ERROR_UTIL_ERROR_CLASS_DOESNT_EXIST, array('class' => $callback[0])); } if (!in_array(strtolower($callback[1]), get_class_methods($callback[0]))) { return Error_Raise::exception('Error_Util', ERROR_UTIL_ERROR_METHOD_DOESNT_EXIST, array('method' => $callback[1], 'class' => $callback[0])); } return true; } elseif (is_object($callback[0])) { if (!method_exists($callback[0], $callback[1])) { return Error_Raise::exception('Error_Util', ERROR_UTIL_ERROR_METHOD_DOESNT_EXIST, array('method' => $callback[1], 'class' => get_class($callback[0]))); } return true; } else { return Error_Raise::exception('Error_Util', ERROR_UTIL_ERROR_INVALID_INPUT, array('expected' => array('array', 'string'), 'was' => gettype($callback[0]), 'var' => '$callback[0]', 'paramnum' => 1)); } // is a callback method return true; } return Error_Raise::exception('error_util', ERROR_UTIL_ERROR_INVALID_INPUT, array('expected' => array('array', 'string'), 'was' => gettype($callback), 'var' => '$callback', 'paramnum' => 1)); }
/** * Returns the progress attributes. Assoc array (defaut) or string. * * @param bool $asString (optional) whether to return the attributes as string * * @return mixed * @since 1.0 * @access public * @throws HTML_PROGRESS_ERROR_INVALID_INPUT * @see setProgressAttributes() */ function getProgressAttributes($asString = false) { if (!is_bool($asString)) { return Error_Raise::exception($this->_package, HTML_PROGRESS_ERROR_INVALID_INPUT, array('var' => '$asString', 'was' => gettype($asString), 'expected' => 'boolean', 'paramnum' => 1)); } $attr = $this->_progress['progress']; if ($asString) { return $this->_getAttrString($attr); } else { return $attr; } }