* @author Jon Parise <jon@horde.org>
* @package Core
*/
-
-/* Log (need to include because of constants). */
-include_once 'Log.php';
-
class Horde
{
/**
/**
* Logs a message to the global Horde log backend.
*
- * @param mixed $message Either a string or a PEAR_Error object.
+ * @param mixed $message Either a string or an object with a
+ * getMessage() method (e.g. PEAR_Error,
+ * Exception).
* @param string $file What file was the log function called from
* (e.g. __FILE__)?
* @param integer $line What line was the log function called from
return;
}
- if (is_a($message, 'PEAR_Error')) {
+ if ($message instanceof PEAR_Error) {
$userinfo = $message->getUserInfo();
$message = $message->getMessage();
if (!empty($userinfo)) {
empty($conf['log']['name']) ||
empty($conf['log']['ident']) ||
!isset($conf['log']['params'])) {
- self::fatal(PEAR::raiseError('Horde is not correctly configured to log error messages. You must configure at least a text file log in horde/config/conf.php.'), __FILE__, __LINE__, false);
+ self::fatal(new Horde_Exception('Horde is not correctly configured to log error messages. You must configure at least a text file log in horde/config/conf.php.'), __FILE__, __LINE__, false);
}
self::$_logger = Log::singleton($conf['log']['type'],
$conf['log']['ident'],
$conf['log']['params']);
if (!is_a(self::$_logger, 'Log')) {
- self::fatal(PEAR::raiseError('An error has occurred. Furthermore, Horde encountered an error attempting to log this error. Please check your Horde logging configuration in horde/config/conf.php.'), __FILE__, __LINE__, false);
+ self::fatal(new Horde_Exception('An error has occurred. Furthermore, Horde encountered an error attempting to log this error. Please check your Horde logging configuration in horde/config/conf.php.'), __FILE__, __LINE__, false);
}
return self::$_logger;
/**
* Aborts with a fatal error, displaying debug information to the user.
*
- * @param mixed $error A PEAR_Error object with debug information or an
- * error message.
+ * @param mixed $error Either a string or an object with a getMessage()
+ * method (e.g. PEAR_Error, Exception).
+ * @todo Better Exception handling
* @param integer $file The file in which the error occured.
* @param integer $line The line on which the error occured.
* @param boolean $log Log this message via logMessage()?
*/
- static public function fatal($error, $file, $line, $log = true)
+ static public function fatal($error, $file = null, $line = null,
+ $log = true)
{
$admin = Horde_Auth::isAdmin();
$cli = Horde_Cli::runningFromCLI();
$errortext = '<h1>' . _("A fatal error has occurred") . '</h1>';
- if (is_a($error, 'PEAR_Error')) {
+ if ($error instanceof PEAR_Error) {
$info = array_merge(array('file' => 'conf.php', 'variable' => '$conf'),
array($error->getUserInfo()));
$errortext .= '<h3>' . htmlspecialchars($error) . '</h3>';
}
+ if (is_null($file) && $error instanceof Exception) {
+ $file = $error->getFile();
+ }
+ if (is_null($line) && $error instanceof Exception) {
+ $line = $error->getLine();
+ }
+
if ($admin) {
$errortext .= '<p><code>' . sprintf(_("[line %d of %s]"), $line, $file) . '</code></p>';
if (is_object($error)) {
*
* @return mixed The value of $var_names, in a compact()'ed array if
* $var_names is an array.
+ * @throws Horde_Exception
*/
static public function loadConfiguration($config_file, $var_names = null,
$app = null, $show_output = false)
$output = ob_get_clean();
if (!empty($output) && !$show_output) {
- return PEAR::raiseError(sprintf('Failed to import configuration file "%s": ', $file) . strip_tags($output));
+ throw new Horde_Exception(sprintf('Failed to import configuration file "%s": ', $file) . strip_tags($output));
}
if (!$success) {
- return PEAR::raiseError(sprintf('Failed to import configuration file "%s".', $file));
+ throw new Horde_Exception(sprintf('Failed to import configuration file "%s".', $file));
}
$was_included = true;
$output = ob_get_clean();
if (!empty($output) && !$show_output) {
- return PEAR::raiseError(sprintf('Failed to import configuration file "%s": ', $file) . strip_tags($output));
+ throw new Horde_Exception(sprintf('Failed to import configuration file "%s": ', $file) . strip_tags($output));
}
if (!$success) {
- return PEAR::raiseError(sprintf('Failed to import configuration file "%s".', $file));
+ throw new Horde_Exception(sprintf('Failed to import configuration file "%s".', $file));
}
$was_included = true;
// Return an error if neither main or vhosted versions of the config
// file exist.
if (!$was_included) {
- return PEAR::raiseError(sprintf('Failed to import configuration file "%s".', $config_dir . $config_file));
+ throw new Horde_Exception(sprintf('Failed to import configuration file "%s".', $config_dir . $config_file));
}
if (isset($output) && $show_output) {
*
* @return array A hash with the VFS parameters; the VFS driver in 'type'
* and the connection parameters in 'params'.
+ * @throws Horde_Exception
*/
static public function getVFSConfig($name)
{
global $conf;
if (!isset($conf[$name]['type'])) {
- return PEAR::raiseError(_("You must configure a VFS backend."));
+ throw new Horde_Exception(_("You must configure a VFS backend."));
}
$vfs = ($conf[$name]['type'] == 'horde')
$fileroot = isset($registry) ? $registry->get('fileroot') : '';
if (!is_array($params) || !count($params)) {
- self::fatal(PEAR::raiseError(
+ self::fatal(new Horde_Exception(
sprintf(_("No configuration information specified for %s."), $name) . "\n\n" .
sprintf(_("The file %s should contain some %s settings."),
$fileroot . '/config/' . $file,
foreach ($fields as $field) {
if (!isset($params[$field])) {
- self::fatal(PEAR::raiseError(
+ self::fatal(new Horde_Exception(
sprintf(_("Required \"%s\" not specified in %s configuration."), $field, $name) . "\n\n" .
sprintf(_("The file %s should contain a %s setting."),
$fileroot . '/config/' . $file,
array(&$sh, 'gc'));
$GLOBALS['horde_sessionhandler'] = $sh;
} catch (Horde_Exception $e) {
- self::fatal(PEAR::raiseError('Horde is unable to correctly start the custom session handler.'), __FILE__, __LINE__, false);
+ self::fatal(new Horde_Exception('Horde is unable to correctly start the custom session handler.'), __FILE__, __LINE__, false);
}
}
}
* the failure.
*
* @return mixed Either the results of the hook or PEAR error on failure.
+ * @todo Throw Horde_Exception
*/
static public function callHook($hook, $args = array(), $app = 'horde',
$error = 'PEAR_Error')
{
if (!isset(self::$_hooksLoaded[$app])) {
- $success = self::loadConfiguration('hooks.php', null, $app);
- if (is_a($success, 'PEAR_Error')) {
- self::logMessage($success, __FILE__, __LINE__, PEAR_LOG_DEBUG);
- self::$_hooksLoaded[$app] = false;
- } else {
+ try {
+ self::loadConfiguration('hooks.php', null, $app);
self::$_hooksLoaded[$app] = true;
+ } catch (Horde_Exception $e) {
+ self::logMessage($e, __FILE__, __LINE__, PEAR_LOG_DEBUG);
+ self::$_hooksLoaded[$app] = false;
}
}
if (function_exists($hook)) {
$result = call_user_func_array($hook, $args);
- if (is_a($result, 'PEAR_Error')) {
+ if ($result instanceof PEAR_Error) {
self::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
}
return $result;
* Create a new Horde_Registry instance.
*
* @param integer $session_flags Any session flags.
+ *
+ * @throws Horde_Exception
*/
protected function __construct($session_flags = 0)
{
/* Import and global Horde's configuration values. */
$this->_cache['conf-horde'] = Horde::loadConfiguration('conf.php', 'conf', 'horde');
- if (is_a($this->_cache['conf-horde'], 'PEAR_Error')) {
- return $this->_cache['conf-horde'];
- }
$conf = $GLOBALS['conf'] = &$this->_cache['conf-horde'];
* scripts that handle login.
*
* @return boolean Whether or not the _appStack was modified.
- * Return PEAR_Error on error.
+ * @throws Horde_Exception
*/
public function pushApp($app, $checkPerms = true)
{
Horde_Nls::setLanguageEnvironment($GLOBALS['language'], $app);
/* Import this application's configuration values. */
- $success = $this->importConfig($app);
- if (is_a($success, 'PEAR_Error')) {
- return $success;
- }
+ $this->importConfig($app);
/* Load preferences after the configuration has been loaded to make
* sure the prefs file has all the information it needs. */
* app to whichever app was current before this one took over.
*
* @return string The name of the application that was popped.
+ * @throws Horde_Exception
*/
public function popApp()
{
*
* @param string $app The name of the application.
*
- * @return boolean True on success, PEAR_Error on error.
+ * @throws Horde_Exception
*/
public function importConfig($app)
{
if (($app != 'horde') &&
!$this->_loadCacheVar('conf-' . $app)) {
- $success = Horde::loadConfiguration('conf.php', 'conf', $app);
- if (is_a($success, 'PEAR_Error')) {
- return $success;
- }
- $this->_cache['conf-' . $app] = Horde_Array::array_merge_recursive_overwrite($this->_cache['conf-horde'], $success);
+ $this->_cache['conf-' . $app] = Horde_Array::array_merge_recursive_overwrite($this->_cache['conf-horde'], Horde::loadConfiguration('conf.php', 'conf', $app));
$this->_saveCacheVar('conf-' . $app);
}
$GLOBALS['conf'] = &$this->_cache['conf-' . $app];
-
- return true;
}
/**