Add Horde_Registry_Application
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 6 Aug 2009 04:27:53 +0000 (22:27 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 11 Aug 2009 18:50:05 +0000 (12:50 -0600)
framework/Core/lib/Horde/Registry.php
framework/Core/lib/Horde/Registry/Api.php
framework/Core/lib/Horde/Registry/Application.php [new file with mode: 0644]
framework/Core/package.xml

index 43c7c1e..d2f1bc7 100644 (file)
@@ -345,7 +345,7 @@ class Horde_Registry
 
         foreach (array_keys($this->applications) as $app) {
             if (in_array($this->applications[$app]['status'], $status)) {
-                $api = $this->_getApiOb($app);
+                $api = $this->_getOb($app, 'api');
                 $this->_cache['api'][$app] = array(
                     'api' => array_diff(get_class_methods($api), array('__construct'), $api->disabled),
                     'links' => $api->links,
@@ -358,32 +358,35 @@ class Horde_Registry
     }
 
     /**
-     * Retrieve the API object for a given application.
+     * Retrieve an API object.
      *
-     * @param string $app  The application to load.
+     * @param string $app   The application to load.
+     * @param string $type  Either 'application' or 'api'.
      *
-     * @return Horde_Registry_Api  The API object.
+     * @return Horde_Registry_Api|Horde_Registry_Application  The API object.
      * @throws Horde_Exception
      */
-    protected function _getApiOb($app)
+    protected function _getOb($app, $type)
     {
-        if (isset($this->_cache['apiob'][$app])) {
-            return $this->_cache['apiob'][$app];
+        if (isset($this->_cache['ob'][$app][$type])) {
+            return $this->_cache['ob'][$app][$type];
         }
 
+        $cname = Horde_String::ucfirst($type);
+
         /* Can't autoload here, since the application may not have been
          * initialized yet. */
-        $classname = Horde_String::ucfirst($app) . '_Api';
-        $path = $this->get('fileroot', $app) . '/lib/Api.php';
+        $classname = Horde_String::ucfirst($app) . '_' . $cname;
+        $path = $this->get('fileroot', $app) . '/lib/' . $cname . '.php';
         if (file_exists($path)) {
             include_once $path;
         } else {
-            $classname = 'Horde_Registry_Api';
+            $classname = 'Horde_Registry_' . $cname;
         }
 
-        $this->_cache['apiob'][$app] = new $classname;
+        $this->_cache['ob'][$app][$type] = new $classname;
 
-        return $this->_cache['apiob'][$app];
+        return $this->_cache['ob'][$app][$type];
     }
 
     /**
@@ -566,7 +569,7 @@ class Horde_Registry
         }
 
         /* Load the API now. */
-        $api = $this->_getApiOb($app);
+        $api = $this->_getOb($app, 'api');
 
         /* Make sure that the function actually exists. */
         if (!method_exists($api, $call)) {
@@ -1027,7 +1030,7 @@ class Horde_Registry
         }
 
         try {
-            $api = $this->_getApiOb($app);
+            $api = $this->_getOb($app, 'application');
             return $api->version;
         } catch (Horde_Exception $e) {
             return 'unknown';
@@ -1048,7 +1051,7 @@ class Horde_Registry
         }
 
         try {
-            $api = $this->_getApiOb($app);
+            $api = $this->_getOb($app, 'application');
             return $api->mobileView;
         } catch (Horde_Exception $e) {
             return false;
index 5efd64d..3c45c33 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * Template class for application API files.
+ * Default class for application defined API calls.
  *
  * Copyright 2009 The Horde Project (http://www.horde.org/)
  *
 class Horde_Registry_Api
 {
     /**
-     * Does this application support a mobile view?
-     *
-     * @var boolean
-     */
-    public $mobileView = false;
-
-    /**
-     * The application's version.
-     *
-     * @var string
-     */
-    public $version = 'unknown';
-
-    /**
      * Links.
      *
      * @var array
diff --git a/framework/Core/lib/Horde/Registry/Application.php b/framework/Core/lib/Horde/Registry/Application.php
new file mode 100644 (file)
index 0000000..32fd226
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+/**
+ * Default class for the Horde Application API.
+ *
+ * Copyright 2009 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @author  Michael Slusarz <slusarz@horde.org>
+ * @package Core
+ */
+class Horde_Registry_Application
+{
+    /**
+     * Does this application support a mobile view?
+     *
+     * @var boolean
+     */
+    public $mobileView = false;
+
+    /**
+     * The application's version.
+     *
+     * @var string
+     */
+    public $version = 'unknown';
+
+    /**
+     * The list of disabled API calls.
+     *
+     * @var array
+     */
+    public $disabled = array();
+
+}
index cf47b34..fade2bb 100644 (file)
@@ -37,7 +37,7 @@ Application Framework.
   <api>beta</api>
  </stability>
  <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>* Added Horde_Registry_Api:: template class.
+ <notes>* Added Horde_Registry_Api:: and Horde_Registry_Application:: classes.
  * Moved Horde_Exception to Exception package.
  * Renamed Menu:: as Horde_Menu::.
  * Renamed Help:: as Horde_Help::.
@@ -58,6 +58,7 @@ Application Framework.
      <file name="Registry.php" role="php" />
      <dir name="Registry">
       <file name="Api.php" role="php" />
+      <file name="Application.php" role="php" />
       <file name="Caller.php" role="php" />
      </dir> <!-- /lib/Horde/Registry -->
      <dir name="Script">
@@ -128,6 +129,7 @@ Application Framework.
    <install name="lib/Horde/Menu.php" as="Horde/Menu.php" />
    <install name="lib/Horde/Registry.php" as="Horde/Registry.php" />
    <install name="lib/Horde/Registry/Api.php" as="Horde/Registry/Api.php" />
+   <install name="lib/Horde/Registry/Application.php" as="Horde/Registry/Application.php" />
    <install name="lib/Horde/Registry/Caller.php" as="Horde/Registry/Caller.php" />
    <install name="lib/Horde/Script/Files.php" as="Horde/Script/Files.php" />
    <install name="lib/Horde.php" as="Horde.php" />