Remove $services and $types vars from API interface
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 5 Aug 2009 23:02:02 +0000 (17:02 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 5 Aug 2009 23:02:02 +0000 (17:02 -0600)
framework/Core/lib/Horde/Registry.php
framework/Core/lib/Horde/Registry/Api.php

index 9d3f5e9..43c7c1e 100644 (file)
@@ -242,7 +242,7 @@ class Horde_Registry
     public function clearCache()
     {
         unset($_SESSION['_registry']);
-        $this->_saveCacheVar('apicache', true);
+        $this->_saveCacheVar('api', true);
         $this->_saveCacheVar('appcache', true);
     }
 
@@ -331,9 +331,7 @@ class Horde_Registry
     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;
         }
 
@@ -345,50 +343,18 @@ 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)) {
-                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');
     }
 
     /**
@@ -495,7 +461,7 @@ class Horde_Registry
                         }
                     } 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;
                             }
                         }
@@ -508,44 +474,6 @@ 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.
@@ -586,7 +514,9 @@ class Horde_Registry
 
         $this->_loadApiCache();
 
-        return empty($this->_cache['api'][$app][$call]) ? false : $app;
+        return in_array($call, $this->_cache['api'][$app]['api'])
+            ? $app
+            : false;
     }
 
     /**
@@ -643,14 +573,10 @@ 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' => $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);
@@ -724,12 +650,12 @@ class Horde_Registry
 
         /* 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) {
index 9d1f077..5efd64d 100644 (file)
@@ -2,81 +2,6 @@
 /**
  * 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
@@ -102,50 +27,29 @@ class Horde_Registry_Api
     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. */
 
 }