Horde_Perms now created with Horde_Injector
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 11 Feb 2010 19:58:14 +0000 (12:58 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 11 Feb 2010 20:04:00 +0000 (13:04 -0700)
beatnik/lib/Beatnik.php
framework/Core/lib/Horde/Core/Binder/Perms.php [new file with mode: 0644]
framework/Core/lib/Horde/Registry.php
framework/Core/package.xml
framework/Kolab_Storage/test/Horde/Kolab/Storage/Scenario.php
framework/Perms/lib/Horde/Perms.php
shout/lib/Shout.php

index 03c55d5..9553507 100644 (file)
@@ -449,19 +449,18 @@ class Beatnik {
             return true;
         }
 
-        $perms = Horde_Perms::singleton();
         if ($permmask === null) {
-            $permmask = Horde_Perms::SHOW|Horde_Perms::READ;
+            $permmask = Horde_Perms::SHOW | Horde_Perms::READ;
         }
 
         # Default deny all permissions
         $user = 0;
         $superadmin = 0;
 
-        $superadmin = $perms->hasPermission('beatnik:domains', Horde_Auth::getAuth(), $permmask);
+        $superadmin = $GLOBALS['perms']->hasPermission('beatnik:domains', Horde_Auth::getAuth(), $permmask);
 
         while ($numparents >= 0) {
-            $tmpuser = $perms->hasPermission($permname, Horde_Auth::getAuth(), $permmask);
+            $tmpuser = $GLOBALS['perms']->hasPermission($permname, Horde_Auth::getAuth(), $permmask);
 
             $user = $user | $tmpuser;
             if ($numparents > 0) {
diff --git a/framework/Core/lib/Horde/Core/Binder/Perms.php b/framework/Core/lib/Horde/Core/Binder/Perms.php
new file mode 100644 (file)
index 0000000..a3ad522
--- /dev/null
@@ -0,0 +1,24 @@
+<?php
+class Horde_Core_Binder_Perms implements Horde_Injector_Binder
+{
+    public function create(Horde_Injector $injector)
+    {
+        $perm_driver = $perm_params = null;
+
+        if (empty($GLOBALS['conf']['perms']['driver'])) {
+            $perm_driver = empty($GLOBALS['conf']['datatree']['driver'])
+                ? null
+                : 'datatree';
+        } else {
+            $perm_driver = $GLOBALS['conf']['perms']['driver'];
+            $perm_params = Horde::getDriverConfig('perms', $perm_driver);
+        }
+
+        return Horde_Perms::factory($perm_driver, $perm_params);
+    }
+
+    public function equals(Horde_Injector_Binder $binder)
+    {
+        return false;
+    }
+}
index f261ac8..e5366ca 100644 (file)
@@ -232,6 +232,7 @@ class Horde_Registry
         $injector->addBinder('Horde_Db_Adapter_Base', new Horde_Core_Binder_Db('reader'));
         $injector->addBinder('Horde_Log_Logger', new Horde_Core_Binder_Logger());
         $injector->addBinder('Horde_Memcache', new Horde_Core_Binder_Memcache());
+        $injector->addBinder('Horde_Perms', new Horde_Core_Binder_Perms());
         $injector->addBinder('Horde_Template', new Horde_Core_Binder_Template());
         $injector->addBinder('Net_DNS_Resolver', new Horde_Core_Binder_Dns());
 
@@ -314,9 +315,7 @@ class Horde_Registry
         }
 
         /* Create the global permissions object. */
-        // TODO: Convert to using Horde_Injector
-        $GLOBALS['perms'] = Horde_Perms::singleton();
-        $injector->setInstance('Horde_Perms', $GLOBALS['perms']);
+        $GLOBALS['perms'] = $injector->getInstance('Horde_Perms');
 
         /* Initialize notification object. Always attach status listener by
          * default. */
index 6dd5560..3b4f4e8 100644 (file)
@@ -66,6 +66,7 @@ Application Framework.
        <file name="Dns.php" role="php" />
        <file name="Logger.php" role="php" />
        <file name="Memcache.php" role="php" />
+       <file name="Perms.php" role="php" />
        <file name="Template.php" role="php" />
       </dir> <!-- /lib/Horde/Core/Binder -->
      </dir> <!-- /lib/Horde/Core -->
@@ -155,6 +156,7 @@ Application Framework.
    <install name="lib/Horde/Core/Binder/Dns.php" as="Horde/Core/Binder/Dns.php" />
    <install name="lib/Horde/Core/Binder/Logger.php" as="Horde/Core/Binder/Logger.php" />
    <install name="lib/Horde/Core/Binder/Memcache.php" as="Horde/Core/Binder/Memcache.php" />
+   <install name="lib/Horde/Core/Binder/Perms.php" as="Horde/Core/Binder/Perms.php" />
    <install name="lib/Horde/Core/Binder/Template.php" as="Horde/Core/Binder/Template.php" />
    <install name="lib/Horde/ErrorHandler.php" as="Horde/ErrorHandler.php" />
    <install name="lib/Horde/Exception/HookNotSet.php" as="Horde/Exception/HookNotSet.php" />
index 267adc1..3a74ac2 100644 (file)
@@ -312,10 +312,6 @@ EOD;
         $this->prepareRegistry();
         $this->prepareNotification();
 
-        if (!isset($GLOBALS['perms'])) {
-            $GLOBALS['perms'] = Horde_Perms::singleton();
-        }
-
         /** Provide the horde registry */
         $GLOBALS['registry'] = new Horde_Registry();
 
index 65c09af..18ca2a1 100644 (file)
@@ -39,13 +39,6 @@ class Horde_Perms
     protected $_appPerms;
 
     /**
-     * Singleton instance.
-     *
-     * @var array
-     */
-    static protected $_instance = null;
-
-    /**
      * Cache for integerToArray().
      *
      * @var array
@@ -83,34 +76,6 @@ class Horde_Perms
     }
 
     /**
-     * Attempts to return a reference to a concrete instance.
-     * It will only create a new instance if no instance currently exists.
-     *
-     * This method must be invoked as: $var = Horde_Perms::singleton()
-     *
-     * @return Horde_Perms  The concrete reference.
-     * @throws Horde_Perms_Exception
-     */
-    static public function singleton()
-    {
-        if (is_null(self::$_instance)) {
-            $perm_driver = $perm_params = null;
-            if (empty($GLOBALS['conf']['perms']['driver'])) {
-                $perm_driver = empty($GLOBALS['conf']['datatree']['driver'])
-                    ? null
-                    : 'datatree';
-            } else {
-                $perm_driver = $GLOBALS['conf']['perms']['driver'];
-                $perm_params = Horde::getDriverConfig('perms', $perm_driver);
-            }
-
-            self::$_instance = self::factory($perm_driver, $perm_params);
-        }
-
-        return self::$_instance;
-    }
-
-    /**
      * Returns the available permissions for a given level.
      *
      * @param string $name  The permission's name.
index d2f3a14..bcdf0d5 100644 (file)
@@ -52,7 +52,6 @@ class Shout
     static public function getTabs($context, &$vars)
     {
         global $shout;
-        $perms = &Horde_Perms::singleton();
 
         $permprefix = 'shout:contexts:' . $context;
 
@@ -99,20 +98,19 @@ class Shout
     {
         if (Horde_Auth::isAdmin()) { return true; }
 
-        $perms = &Horde_Perms::singleton();
         if ($permmask === null) {
-            $permmask = PERMS_SHOW|PERMS_READ;
+            $permmask = Horde_Perms::SHOW | Horde_Perms::READ;
         }
 
         # Default deny all permissions
         $user = 0;
         $superadmin = 0;
 
-        $superadmin = $perms->hasPermission('shout:superadmin',
+        $superadmin = $GLOBALS['perms']->hasPermission('shout:superadmin',
             Horde_Auth::getAuth(), $permmask);
 
         while ($numparents >= 0) {
-            $tmpuser = $perms->hasPermission($permname,
+            $tmpuser = $GLOBALS['perms']->hasPermission($permname,
                 Horde_Auth::getAuth(), $permmask);
 
             $user = $user | $tmpuser;