Modules
- HTTP_Exception
- HTTP_Exception_400
- HTTP_Exception_401
- HTTP_Exception_402
- HTTP_Exception_403
- HTTP_Exception_404
- HTTP_Exception_405
- HTTP_Exception_406
- HTTP_Exception_407
- HTTP_Exception_408
- HTTP_Exception_409
- HTTP_Exception_410
- HTTP_Exception_411
- HTTP_Exception_412
- HTTP_Exception_413
- HTTP_Exception_414
- HTTP_Exception_415
- HTTP_Exception_416
- HTTP_Exception_417
- HTTP_Exception_500
- HTTP_Exception_501
- HTTP_Exception_502
- HTTP_Exception_503
- HTTP_Exception_504
- HTTP_Exception_505
- Kohana_Exception
- Request_Exception
- Session_Exception
- UTF8_Exception
- Validation_Exception
- View_Exception
Deputy
extends Kohana_Deputy
Deputy ACL
Class declared in MODPATH/deputy/classes/deputy.php on line 11.
Properties
Constants
WILDCARD
string(1) "*"DELIMITER
string(1) "/"
Properties
protected
array$_configConfiguration
protected
Deputy_Resource$_resourcesParent resource
protected
array$_rolesRoles
Methods
public __construct( ) (defined in Kohana_Deputy)
Initialize Account
Return Values
void
Source Code
public function __construct(array $config = array())
{
// Create root resource
$this->_resources = new Deputy_Resource;
// Handle configuration
$this->_config = Arr::merge(Kohana::$config->load('deputy')->as_array(), $config);
// Setup Deputy
$this->_setup();
}
public allowed( ) (defined in Kohana_Deputy)
Is Allowed
Return Values
bool
Source Code
public function allowed($uri)
{
foreach ($this->_roles as $role)
{
if ($role->is_denied($uri))
return FALSE;
if ($role->is_allowed($uri))
return TRUE;
}
return FALSE;
}
public get( string $uri [, bool $create = bool TRUE ] ) (defined in Kohana_Deputy)
Traverse Resource tree for child based on URI structure "parent/child/child/child"
Parameters
-
string$uri required - URI of resource to retrieve. -
bool$create = bool TRUE - Create resource if it does not exist.
Return Values
Deputy_Resource
Source Code
public function get($uri, $create = TRUE)
{
$resource = $this->_resources;
foreach (explode(Deputy::DELIMITER, $uri) as $segment)
if ( ! $resource = $resource->get($segment))
break;
if ( ! $resource && $create)
{
$this->set($uri);
$resource = $this->get($uri, FALSE);
}
return $resource;
}
public get_resources( ) (defined in Kohana_Deputy)
Get Resources
Return Values
array
Source Code
public function get_resources()
{
return $this->_resources;
}
public get_role( ) (defined in Kohana_Deputy)
Get role
Return Values
Deputy_Role
Source Code
public function get_role($name, $default = FALSE)
{
if (isset($this->_roles[$name]))
return $this->_roles[$name];
else
return $default;
}
public get_roles( ) (defined in Kohana_Deputy)
Get roles
Return Values
array
Source Code
public function get_roles()
{
return $this->_roles;
}
public html_link( string $uri [, array $attributes = array(0) , bool $check = bool TRUE ] ) (defined in Kohana_Deputy)
Generate link
Parameters
-
string$uri required -
array$attributes = array(0) -
bool$check = bool TRUE
Return Values
string|NULL
Source Code
public function html_link($uri, $attributes = array(), $check = TRUE)
{
if ($check && ! $this->allowed($uri))
return NULL;
$resource = $this->get($uri);
return html::anchor($resource->get_uri(), $resource->get_title(), $attributes);
}
public html_list( [ Deputy_Resource|NULL $resources = NULL ] ) (defined in Kohana_Deputy)
Get HTML Tree
Parameters
-
Deputy_Resource|NULL$resources = NULL
Return Values
array
Source Code
public function & html_list(Deputy_Resource $resources = NULL)
{
$resources = $resources ? $resources : $this->get_resources();
$tree = array();
foreach ($resources as $resource)
{
if ($resource->is_visible())
{
$key = html::anchor($resource->get_uri(), $resource->get_title());
$value = array();
if (count($resource) > 0)
{
$value = $this->html_list($resource);
}
$tree[$key] = $value;
}
}
return $tree;
}
public static instance( ) (defined in Kohana_Deputy)
Singleton Pattern
Return Values
Deputy
Source Code
public static function instance(array $config = array())
{
static $instance;
if ($instance === NULL)
{
$instance = new Deputy($config);
}
return $instance;
}
public static link( string $uri [, bool $attributes = array(0) , $check = bool TRUE ] ) (defined in Kohana_Deputy)
Helper for html link
Parameters
-
string$uri required -
bool$attributes = array(0) -
unknown$check = bool TRUE
Return Values
string|NULL
Source Code
public static function link($uri, $attributes = array(), $check = TRUE)
{
return Deputy::instance()->html_link($uri, $attributes, $check);
}
public set( string $uri [, Deputy_Resource|NULL $resource = NULL ] ) (defined in Kohana_Deputy)
Set Resource
Parameters
-
string$uri required -
Deputy_Resource|NULL$resource = NULL
Return Values
$this
Source Code
public function set($uri, Deputy_Resource $resource = NULL)
{
$resource = ($resource) ? $resource : Deputy_Resource::factory(array('uri' => $uri));
$segments = explode(Deputy::DELIMITER, $uri);
$count = count($segments);
$pointer = $this->_resources;
$base = array();
foreach ($segments as $index => $segment)
{
$base[] = $segment;
if ($index + 1 == $count)
{
$pointer->set($segment, $resource);
}
else
{
$parent = $pointer->get($segment);
if ( ! $parent)
{
$parent = Deputy_Resource::factory(array('uri' => implode(Deputy::DELIMITER, $base)));
$pointer->set($segment, $parent);
}
$pointer = $parent;
}
}
return $this;
}
public set_resources( ) (defined in Kohana_Deputy)
Add Resources using array conventions
Return Values
$this
Source Code
public function set_resources(array $resources)
{
foreach ($resources as $key => $value)
{
if ( ! $value instanceof Deputy_Resource)
{
$config = array();
if (is_int($key))
{
$config['uri'] = $value;
}
else if (is_string($value))
{
$config['uri'] = $key;
$config['title'] = $value;
}
else if (is_array($value))
{
$value['uri'] = $key;
$config = $value;
}
else if (is_bool($value))
{
$config['uri'] = $key;
$config['visible'] = $value;
}
$value = Deputy_Resource::factory($config);
}
$uri = is_string($key) ? $key : $value->uri();
$this->set($uri, $value);
}
return $this;
}
public set_role( string $name , mixed $role ) (defined in Kohana_Deputy)
Set role
If Deputy_Role passed, it always sets
Parameters
-
string$name required -
mixed$role required - Array|Deputy_Role
Return Values
$this
Source Code
public function set_role($name, $role)
{
if (isset($this->_roles[$name]) && is_array($role))
{
$acl_role = $this->_roles[$name];
}
else
{
$acl_role = ($role instanceof Deputy_Role) ? $role : Deputy_Role::factory();
$this->_roles[$name] = $acl_role;
}
if (is_array($role))
{
$allow = $deny = array();
if (isset($role['allow']) OR isset($role['deny']))
{
$allow = (isset($role['allow'])) ? $role['allow'] : array();
$deny = (isset($role['deny'])) ? $role['deny'] : array();
}
else
{
$allow = $role;
}
$acl_role->allow_many($allow);
$acl_role->deny_many($deny);
}
return $this;
}
public set_roles( ) (defined in Kohana_Deputy)
Set Roles
Return Values
$this
Source Code
public function set_roles(array $roles)
{
foreach ($roles as $name => $role)
{
$this->set_role($name, $role);
}
return $this;
}
protected _setup( ) (defined in Kohana_Deputy)
Setup
Return Values
void
Source Code
protected function _setup()
{
if ($this->_config['autoload'])
{
$this->set_resources($this->_config['resources']);
}
}