All pastes #134987 Raw Edit

Stuff

public php v1 · immutable
#134987 ·published 2006-08-16 16:53 UTC
rendered paste body
<?phpclass AgaviRbacConfigHandler extends AgaviConfigHandler{	public function execute($config, $context = null)	{		$user = AgaviContext::getInstance($context)->getUser();		if($context == null) {			$context = '';		}		$configurations = $this->orderConfigurations(AgaviConfigCache::parseConfig($config, true, $this->getValidationFile())->configurations, AgaviConfig::get('core.environment'), $context);		$data = array();		foreach($configurations as $cfg)		{			if(isset($cfg->roles) )			{				$this->parseHierarchy($user, $cfg->roles);			}		}		$code = '$this->importHierarchy(' . var_export($user->exportHierarchy(), true) . ');';		// compile data		$retval = "<?php\n" .				  "// auto-generated by ".__CLASS__."\n" .				  "// date: %s GMT\n%s\n?>";		$retval = sprintf($retval, gmdate('m/d/Y H:i:s'), $code);		return $retval;	}	protected function parseHierarchy($user, $roles, $parent = null)	{		foreach($roles as $role)		{			$name = $role->getAttribute('name');			$opts = array();			if($role->hasAttribute('description') )		$opts['description']	= $role->getAttribute('description');			if($role->hasAttribute('global_access') )	$opts['global_access']	= $this->literalize($role->getAttribute('global_access') );			$permissions = array();			if($role->hasChildren('permissions') )			{				foreach($role->permissions as $permission)				{					$permissions[$permission->getAttribute('name')] = true;				}			}			$user->addHierarchy($name, $permissions, $opts, $parent);			if($role->hasChildren('roles') )			{				$this->parseHierarchy($user, $role->roles, $name);			}		}	}}?>