From: Michael M Slusarz Date: Thu, 6 Aug 2009 04:50:33 +0000 (-0600) Subject: Add Horde_Registry::callAppMethod() and hasAppMethod() X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=6fa4df22871c56e94c8d5930dd3d33ac8e0e08ab;p=horde.git Add Horde_Registry::callAppMethod() and hasAppMethod() --- diff --git a/framework/Core/lib/Horde/Registry.php b/framework/Core/lib/Horde/Registry.php index d2f1bc7f0..f681a615e 100644 --- a/framework/Core/lib/Horde/Registry.php +++ b/framework/Core/lib/Horde/Registry.php @@ -324,7 +324,7 @@ class Horde_Registry } /** - * Fills the registry's API cache with the available services and types. + * Fills the registry's API cache with the available external services. * * @throws Horde_Exception */ @@ -523,6 +523,19 @@ class Horde_Registry } /** + * Determine if an application method exists for a given application. + * + * @param string $app The application name. + * @param string $method The full name of the method to check for. + * + * @return boolean Existence of the method. + */ + public function hasAppMethod($app, $method) + { + return method_exists($this->_getOb($app, 'application'), $method); + } + + /** * Return the hook corresponding to the default package that * provides the functionality requested by the $method * parameter. $method is a string consisting of @@ -604,6 +617,55 @@ class Horde_Registry } /** + * Call a private Horde application method. + * + * @param string $app The application name. + * @param string $call The method to call. + * @param array $options Additional options: + *
+     * 'args' - (array) Additional parameters to pass to the method.
+     * 'noperms' - (boolean) If true, don't check the perms.
+     * 
+ * + * @return mixed Various. Returns null if the method doesn't exist. + * @throws Horde_Exception Application methods should throw this if there + * is a fatal error. + */ + public function callAppMethod($app, $call, $options = array()) + { + /* Make sure that the method actually exists. */ + if (!$this->hasAppMethod($app, $call)) { + return null; + } + + /* Load the API now. */ + $api = $this->_getOb($app, 'application'); + + /* Switch application contexts now, if necessary, before + * including any files which might do it for us. Return an + * error immediately if pushApp() fails. */ + $pushed = $this->pushApp($app, array('check_perms' => empty($options['noperms']))); + + try { + $result = call_user_func_array(array($api, $call), empty($options['args']) ? array() : $options['args']); + } catch (Horde_Exception $e) { + $result = $e; + } + + /* If we changed application context in the course of this + * call, undo that change now. */ + if ($pushed === true) { + $this->popApp(); + } + + if ($result instanceof Exception) { + throw $e; + } + + return $result; + } + + /** * Return the hook corresponding to the default package that * provides the functionality requested by the $method * parameter. $method is a string consisting of