Add Permissions API
authorBen Klang <ben@alkaloid.net>
Sat, 5 Jul 2008 15:53:39 +0000 (15:53 +0000)
committerBen Klang <ben@alkaloid.net>
Sun, 10 Jan 2010 04:05:28 +0000 (23:05 -0500)
Make sure cache is initialized when Operator::getAccountCodes() is called staticly

lib/Operator.php
lib/api.php [new file with mode: 0644]

index e31e1a6..1dc2fd7 100644 (file)
@@ -2,7 +2,7 @@
 /**
  * Operator Base Class.
  *
- * $Horde: incubator/operator/lib/Operator.php,v 1.6 2008/07/05 14:38:23 bklang Exp $
+ * $Horde: incubator/operator/lib/Operator.php,v 1.7 2008/07/05 15:53:39 bklang Exp $
  *
  * Copyright 2008 Alkaloid Networks LLC <http://projects.alkaloid.net>
  *
@@ -90,7 +90,13 @@ class Operator {
      */
     function getAccountCodes()
     {
-        global $cache, $operator_driver;
+        global $operator_driver;
+
+        if (!isset($GLOBALS['cache'])) {
+            $cache = &Horde_Cache::singleton($GLOBALS['conf']['cache']['driver'], Horde::getDriverConfig('cache', $GLOBALS['conf']['cache']['driver']));
+        } else {
+            $cache =& $GLOBALS['cache'];
+        }
 
         // Use 0 lifetime to allow cache lifetime to be set when storing the
         // object.
diff --git a/lib/api.php b/lib/api.php
new file mode 100644 (file)
index 0000000..ae92a72
--- /dev/null
@@ -0,0 +1,41 @@
+<?php
+/**
+ * Operator external API interface.
+ *
+ * This file defines Operator's external API interface. Other applications
+ * can interact with Operator through this API.
+ *
+ * $Horde: incubator/operator/lib/api.php,v 1.1 2008/07/05 15:53:39 bklang Exp $
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @package Operator
+ */
+
+$_services['perms'] = array(
+    'args' => array(),
+    'type' => '{urn:horde}stringArray');
+
+function _operator_perms()
+{
+    static $perms = array();
+
+    if (!empty($perms)) {
+        return $perms;
+    }
+
+    @define('OPERATOR_BASE', dirname(__FILE__) . '/..');
+    require_once OPERATOR_BASE . '/lib/base.php';
+
+    $perms['tree']['operator']['accountcodes'] = false;
+    $perms['title']['operator:accountcodes'] = _("Account Codes");
+
+    $accountcodes = Operator::getAccountCodes();
+    foreach ($accountcodes as $accountcode) {
+        $perms['tree']['operator']['accountcodes'][$accountcode] = false;
+        $perms['title']['operator:accountcodes:' . $accountcode] = $accountcode;
+    }
+
+    return $perms;
+}