public function clearCache()
{
unset($_SESSION['_registry']);
- $this->_saveCacheVar('apicache', true);
+ $this->_saveCacheVar('api', true);
$this->_saveCacheVar('appcache', true);
}
protected function _loadApiCache()
{
/* First, try to load from cache. */
- if ($this->_loadCacheVar('apicache')) {
- $this->_cache['api'] = $this->_cache['apicache'][0];
- $this->_cache['type'] = $this->_cache['apicache'][1];
+ if ($this->_loadCacheVar('api')) {
return;
}
$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)) {
- 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;
- }
+ 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
+ );
}
}
- $this->_cache['apicache'] = array(
- // Index 0
- $this->_cache['api'],
- // Index 1
- $this->_cache['type']
- );
- $this->_saveCacheVar('apicache');
+ $this->_saveCacheVar('api');
}
/**
}
} elseif (is_null($api) || ($method == $api)) {
if (isset($this->_cache['api'][$app])) {
- foreach (array_keys($this->_cache['api'][$app]) as $service) {
+ foreach ($this->_cache['api'][$app]['api'] as $service) {
$methods[$method . '/' . $service] = true;
}
}
}
/**
- * 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.
$this->_loadApiCache();
- return empty($this->_cache['api'][$app][$call]) ? false : $app;
+ return in_array($call, $this->_cache['api'][$app]['api'])
+ ? $app
+ : false;
}
/**
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' => $checkPerms));
+ $pushed = $this->pushApp($app, array('check_perms' => !in_array($call, $this->_cache['api'][$app]['noperms'])));
try {
$result = call_user_func_array(array($api, $call), $args);
/* Make sure the link is defined. */
$this->_loadApiCache();
- if (empty($this->_cache['api'][$app][$call]['link'])) {
+ if (empty($this->_cache['api'][$app]['links'][$call])) {
throw new Horde_Exception('The link ' . $call . ' is not defined in ' . $app . '\'s API.');
}
/* Initial link value. */
- $link = $this->_cache['api'][$app][$call]['link'];
+ $link = $this->_cache['api'][$app]['links'][$call];
/* Fill in html-encoded arguments. */
foreach ($args as $key => $val) {
/**
* 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
public $version = 'unknown';
/**
- * The services provided by this application.
- * TODO: Describe structure.
+ * Links.
*
* @var array
*/
- public $services = array(
- 'perms' => array(
- 'args' => array(),
- 'type' => '{urn:horde}hashHash'
- ),
-
- 'changeLanguage' => array(
- 'args' => array(),
- 'type' => 'boolean'
- )
- );
+ public $links = array();
/**
- * TODO
- * TODO: Describe structure.
+ * The listing of API calls that do not require permissions checking.
*
* @var array
*/
- public $types = array();
-
- /* Reserved functions. */
+ public $noPerms = array();
/**
- * Returns a list of available permissions.
+ * The list of disabled API calls.
*
- * @return array The permissions list.
- * TODO: Describe structure.
+ * @var array
*/
- public function perms()
- {
- return array();
- }
+ public $disabled = array();
- /**
- * Called when the language is changed.
- */
- public function changeLanguage()
- {
- 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. */
}