[Fusionforge-commits] r9790 - trunk/gforge/common/include
Roland Mas
lolando at libremir.placard.fr.eu.org
Fri May 21 09:45:47 CEST 2010
Author: lolando
Date: 2010-05-21 09:45:47 +0200 (Fri, 21 May 2010)
New Revision: 9790
Modified:
trunk/gforge/common/include/RBAC.php
Log:
Refactor code for singleton roles
Modified: trunk/gforge/common/include/RBAC.php
===================================================================
--- trunk/gforge/common/include/RBAC.php 2010-05-21 07:45:33 UTC (rev 9789)
+++ trunk/gforge/common/include/RBAC.php 2010-05-21 07:45:47 UTC (rev 9790)
@@ -359,6 +359,18 @@
}
+class SingletonRole extends BaseRole {
+ // This role is implemented as a singleton
+ protected static $_instances = array () ;
+ public static function getInstance() {
+ $c = __CLASS__;
+ if (!isset(self::$_instances[$c])) {
+ self::$_instances[$c] = new $c;
+ }
+ return self::$_instances[$c];
+ }
+}
+
// Actual classes
abstract class RoleExplicit extends BaseRole implements PFO_RoleExplicit {
@@ -373,18 +385,7 @@
}
}
-class RoleAnonymous extends BaseRole implements PFO_RoleAnonymous {
- // This role is implemented as a singleton
- private static $_instance ;
- public static function getInstance() {
- if (!isset(self::$_instance)) {
- $c = __CLASS__;
- self::$_instance = new $c;
- }
-
- return self::$_instance;
- }
-
+class RoleAnonymous extends SingletonRole implements PFO_RoleAnonymous {
public function getID () {
return -PFO_ROLE_ANONYMOUS ;
}
@@ -405,18 +406,7 @@
}
}
-class RoleLoggedIn extends BaseRole implements PFO_RoleLoggedIn {
- // This role is implemented as a singleton
- private static $_instance ;
- public static function getInstance() {
- if (!isset(self::$_instance)) {
- $c = __CLASS__;
- self::$_instance = new $c;
- }
-
- return self::$_instance;
- }
-
+class RoleLoggedIn extends SingletonRole implements PFO_RoleLoggedIn {
public function getID () {
return -PFO_ROLE_LOGGEDIN ;
}
More information about the Fusionforge-commits
mailing list