From: Michael M Slusarz Date: Wed, 5 Aug 2009 23:07:59 +0000 (-0600) Subject: Revert "Remove $services and $types vars from API interface" X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=4ed2b90170e35c1479fb8c33eede6e05f2bdd189;p=horde.git Revert "Remove $services and $types vars from API interface" This reverts commit aa0a1c4a1fe7c0c3c0843e62572005012fca8bac. --- diff --git a/framework/Core/lib/Horde/Registry.php b/framework/Core/lib/Horde/Registry.php index 43c7c1eb3..9d3f5e978 100644 --- a/framework/Core/lib/Horde/Registry.php +++ b/framework/Core/lib/Horde/Registry.php @@ -242,7 +242,7 @@ class Horde_Registry public function clearCache() { unset($_SESSION['_registry']); - $this->_saveCacheVar('api', true); + $this->_saveCacheVar('apicache', true); $this->_saveCacheVar('appcache', true); } @@ -331,7 +331,9 @@ class Horde_Registry protected function _loadApiCache() { /* First, try to load from cache. */ - if ($this->_loadCacheVar('api')) { + if ($this->_loadCacheVar('apicache')) { + $this->_cache['api'] = $this->_cache['apicache'][0]; + $this->_cache['type'] = $this->_cache['apicache'][1]; return; } @@ -343,18 +345,50 @@ class Horde_Registry $this->_cache['api'] = array(); + /* Initialize complex types. */ + $this->_cache['type'] = array( + 'hash' => array( + array('item' => '{urn:horde}hashItem') + ), + 'hashHash' => array( + array('item' => '{urn:horde}hashHashItem') + ), + 'hashItem' => array( + 'key' => 'string', + 'value' => 'string' + ), + 'hashHashItem' => array( + 'key' => 'string', + 'value' => '{urn:horde}hash' + ), + 'stringArray' => array( + array('item' => 'string') + ) + ); + foreach (array_keys($this->applications) as $app) { - if (in_array($this->applications[$app]['status'], $status)) { - $api = $this->_getApiOb($app); - $this->_cache['api'][$app] = array( - 'api' => array_diff(get_class_methods($api), array('__construct'), $api->disabled), - 'links' => $api->links, - 'noperms' => $api->noPerms - ); + if (!in_array($this->applications[$app]['status'], $status)) { + continue; + } + + $api = $this->_getApiOb($app); + $this->_cache['api'][$app] = $api->services; + if (!empty($api->types)) { + foreach ($api->types as $type => $params) { + /* Prefix non-Horde types with the application name. */ + $prefix = ($app == 'horde') ? '' : "${app}_"; + $this->_cache['type'][$prefix . $type] = $params; + } } } - $this->_saveCacheVar('api'); + $this->_cache['apicache'] = array( + // Index 0 + $this->_cache['api'], + // Index 1 + $this->_cache['type'] + ); + $this->_saveCacheVar('apicache'); } /** @@ -461,7 +495,7 @@ class Horde_Registry } } elseif (is_null($api) || ($method == $api)) { if (isset($this->_cache['api'][$app])) { - foreach ($this->_cache['api'][$app]['api'] as $service) { + foreach (array_keys($this->_cache['api'][$app]) as $service) { $methods[$method . '/' . $service] = true; } } @@ -474,6 +508,44 @@ class Horde_Registry } /** + * Returns all of the available registry data types. + * + * @return array The data type list. + */ + public function listTypes() + { + $this->_loadApiCache(); + return $this->_cache['type']; + } + + /** + * Returns a method's signature. + * + * @param string $method The full name of the method to check for. + * + * @return array A two dimensional array. The first element contains an + * array with the parameter names, the second one the return + * type. + */ + public function getSignature($method) + { + if (!($app = $this->hasMethod($method))) { + return false; + } + + $this->_loadApiCache(); + + list(,$function) = explode('/', $method, 2); + if (!empty($function) && + isset($this->_cache['api'][$app][$function]['type']) && + isset($this->_cache['api'][$app][$function]['args'])) { + return array($this->_cache['api'][$app][$function]['args'], $this->_cache['api'][$app][$function]['type']); + } + + return false; + } + + /** * Determine if an interface is implemented by an active application. * * @param string $interface The interface to check for. @@ -514,9 +586,7 @@ class Horde_Registry $this->_loadApiCache(); - return in_array($call, $this->_cache['api'][$app]['api']) - ? $app - : false; + return empty($this->_cache['api'][$app][$call]) ? false : $app; } /** @@ -573,10 +643,14 @@ class Horde_Registry throw new Horde_Exception('The function implementing ' . $call . ' is not defined in ' . $app . '\'s API.'); } + $checkPerms = isset($this->_cache['api'][$app][$call]['checkperms']) + ? $this->_cache['api'][$app][$call]['checkperms'] + : true; + /* 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' => !in_array($call, $this->_cache['api'][$app]['noperms']))); + $pushed = $this->pushApp($app, array('check_perms' => $checkPerms)); try { $result = call_user_func_array(array($api, $call), $args); @@ -650,12 +724,12 @@ class Horde_Registry /* Make sure the link is defined. */ $this->_loadApiCache(); - if (empty($this->_cache['api'][$app]['links'][$call])) { + if (empty($this->_cache['api'][$app][$call]['link'])) { throw new Horde_Exception('The link ' . $call . ' is not defined in ' . $app . '\'s API.'); } /* Initial link value. */ - $link = $this->_cache['api'][$app]['links'][$call]; + $link = $this->_cache['api'][$app][$call]['link']; /* Fill in html-encoded arguments. */ foreach ($args as $key => $val) { diff --git a/framework/Core/lib/Horde/Registry/Api.php b/framework/Core/lib/Horde/Registry/Api.php index 5efd64d60..9d1f0779d 100644 --- a/framework/Core/lib/Horde/Registry/Api.php +++ b/framework/Core/lib/Horde/Registry/Api.php @@ -2,6 +2,81 @@ /** * Template class for application API files. * + * Other Horde-defined API calls + * ============================= + * Horde_Auth_Application:: + * ------------------------ + * 'authLoginParams' => array( + * 'args' => array(), + * 'checkperms' => false, + * 'type' => '{urn:horde}hashHash' + * ), + * 'authAuthenticate' => array( + * 'args' => array( + * 'userID' => 'string', + * 'credentials' => '{urn:horde}hash', + * 'params' => '{urn:horde}hash' + * ), + * 'checkperms' => false, + * 'type' => 'boolean' + * ), + * 'authAuthenticateCallback' => array( + * 'args' => array(), + * 'checkperms' => false + * ), + * 'authTransparent' => array( + * 'args' => array(), + * 'checkperms' => false, + * 'type' => 'boolean' + * ), + * 'authAddUser' => array( + * 'args' => array( + * 'userId' => 'string', + * 'credentials' => '{urn:horde}stringArray' + * ) + * ), + * 'authRemoveUser' => array( + * 'args' => array( + * 'userId' => 'string' + * ) + * ), + * 'authUserList' => array( + * 'type' => '{urn:horde}stringArray' + * ) + * + * Prefs_UI:: + * ---------- + * 'prefsInit' => array( + * 'args' => array(), + * 'type' => '{urn:horde}hashHash' + * ), + * 'prefsHandle' => array( + * 'args' => array( + * 'item' => 'string', + * 'updated' => 'boolean' + * ), + * 'type' => 'boolean' + * ), + * 'prefsCallback' => array( + * 'args' => array() + * ), + * 'prefsMenu' => array( + * 'args' => array(), + * 'type' => 'object' + * ), + * 'prefsStatus' => array( + * 'args' => array() + * ) + * + * TODO: + * ----- + * 'cacheOutput' => array( + * 'args' => array( + * '{urn:horde}hashHash' + * ), + * 'type' => '{urn:horde}hashHash' + * ) + * * Copyright 2009 The Horde Project (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you @@ -27,29 +102,50 @@ class Horde_Registry_Api public $version = 'unknown'; /** - * Links. + * The services provided by this application. + * TODO: Describe structure. * * @var array */ - public $links = array(); + public $services = array( + 'perms' => array( + 'args' => array(), + 'type' => '{urn:horde}hashHash' + ), + + 'changeLanguage' => array( + 'args' => array(), + 'type' => 'boolean' + ) + ); /** - * The listing of API calls that do not require permissions checking. + * TODO + * TODO: Describe structure. * * @var array */ - public $noPerms = array(); + public $types = array(); + + /* Reserved functions. */ /** - * The list of disabled API calls. + * Returns a list of available permissions. * - * @var array + * @return array The permissions list. + * TODO: Describe structure. */ - public $disabled = array(); - + public function perms() + { + return array(); + } - /* API calls should be declared as public functions, with the function - * name corresponding to the API name. Create any internal helper - * functions as protected functions. */ + /** + * Called when the language is changed. + */ + public function changeLanguage() + { + return array(); + } }