[ Index ]

PHP Cross Reference of ACL Module

title

Body

[close]

/components/ -> Strategy.php (source)

   1  <?php
   2  
   3  /**

   4   * This class manages the strategy used for the tree as well as the includes

   5   * and provides the strategy-specific class-names

   6   * 

   7   * @author dispy <dispyfree@googlemail.com>

   8   * @license LGPLv2

   9   * @package acl.base

  10   */
  11  class Strategy {
  12      
  13       /**

  14        * This defines the strategy to use. It's your duty to take care that all requirements

  15        * (e.g. database tables) exist

  16        * @var string

  17        */
  18       public static $strategy = 'nestedSet.pathMaterialization';
  19       
  20       protected static $initialized = false;
  21       
  22       /**

  23        * Assuming you put it there... change it otherwise ^^

  24        * @var string 

  25        */
  26       protected static $location = 'application.modules.acl.';
  27       protected static $config   = NULL;
  28       
  29       public static function initialize(){
  30           if(!static::$initialized){
  31               static::$initialized = true;
  32               $strategyPath = static::$location.'.components.strategies.'.static::$strategy;
  33               Yii::import($strategyPath.'.*');
  34               Yii::import($strategyPath.'.models.*');
  35               $config = require_once(Yii::getPathOfAlias($strategyPath.'.config').'.php');
  36               
  37               if(!$config)
  38                   throw new RuntimeException('Unable to load configuration');
  39               
  40               static::$config = $config;
  41               static::createShortcutClasses();
  42           }
  43       }
  44       
  45       /**

  46        * Gets the class-Name according to the chosen strategy

  47        * @param string $className 

  48        * @return string the resulting class-Name for the strategy

  49        */
  50       public static function getClass($className){
  51           static::initialize();
  52           //If this is a global class

  53           $globalClasses = array('AclObject', 'Action', 'RequestingActiveRecord', 
  54               'RestrictedActiveRecord', 'CGroup', 'RGroup');
  55           if(in_array($className, $globalClasses))
  56                   return $className;
  57           
  58           if(substr($className, 0, strlen(static::$config['prefix'])) == static::$config['prefix'])
  59                   return $className;
  60           
  61           return static::$config['prefix'].$className;
  62       }
  63       
  64       /**

  65        * Returns the given property of the strategy-config

  66        * @param string $propName they key of the property

  67        * @return mixed the value 

  68        */
  69       public static function get($propName){
  70           return @static::$config[$propName];
  71       }
  72       
  73       /**

  74        * Just generates "AGroup" and "RGroup" aka

  75        * "AcessGroup" and "RequestGroup"  dynamically 

  76        */
  77       protected static function createShortcutClasses(){
  78           eval('class CGroup extends '.static::getClass('Aco').'{}');
  79           eval('class RGroup extends '.static::getClass('Aro').'{}');
  80       }
  81       
  82  }
  83  
  84  ?>


Generated: Sun Jul 1 19:24:45 2012 Cross-referenced by PHPXref 0.7.1