ari100krat.local /modules/sprig-aacl/classes/controller/aacl.php

Language PHP Lines 104
MD5 Hash 44487cb374ef05fb121f9ca1e7499c36 Estimated Cost $1,065 (why?)
Repository https://bitbucket.org/seyar/ari100krat.local View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
<?php defined('SYSPATH') or die ('No direct script access.');

/**
 * Base class for access controlled controllers
 * 
 * @see			http://github.com/banks/aacl
 * @package		AACL
 * @uses		Auth
 * @uses		Sprig
 * @author		Paul Banks
 * @copyright	(c) Paul Banks 2010
 * @license		MIT
 */
abstract class Controller_AACL extends Controller_Template implements AACL_Resource
{
	/**
	 * AACL_Resource::acl_id() implementation
	 * 
	 * @return	string 
	 */
	public function acl_id()
	{
		// Controller namespace, controller name
		return 'c:'.strtolower($this->request->controller);
	}
	
	/**
	 * AACL_Resource::acl_actions() implementation
	 * 
	 * @param	bool	$return_current [optional]
	 * @return	mixed
	 */
	public function acl_actions($return_current = FALSE)
	{
		if ($return_current)
		{
			return $this->request->action;
		}
		
		// Find all actions in this class
		$reflection = new ReflectionClass($this);
		
		$actions = array();
		
		// Add all public methods that start with 'action_'
		foreach ($reflection->getMethods(ReflectionMethod::IS_PUBLIC) as $method)
		{
			if (substr($method->name, 0, 7) === 'action_')
			{
				$actions[] = substr($method->name, 7);
			}
		}
		
		return $actions;
	}
	
	/**
	 * AACL_Resource::acl_conditions() implementation
	 * 
	 * @param	Model_User	$user [optional] logged in user model
	 * @param	object    	$condition [optional] condition to test
	 * @return	mixed
	 */
	public function acl_conditions(Model_User $user = NULL, $condition = NULL)
	{
		if (is_null($user) AND is_null($condition))
		{
			// We have no conditions
			return array();
		}
		else
		{
			// We have no conditions so this test should fail!
			return FALSE;
		}
	}
	
	/**
	 * AACL_Resource::acl_instance() implementation
	 * 
	 * Note that the object instance returned should not be used for anything except querying the acl_* methods
	 * 
	 * @param	string	Class name of object required
	 * @return	Object
	 */
	public static function acl_instance($class_name)
	{
		// Return controller instance populated with manipulated request details
		$instance = new $class_name(Request::instance());
		
		$controller_name = strtolower(substr($class_name, 11));
		
		if ($controller_name !== Request::instance()->controller)
		{
			// Manually override controller name and action
			$instance->request->controller = strtolower(substr(get_class($this), 11));
			
			$instance->request->action = NULL;
		}
		
		return $instance;
	}
	
} // End  Controller_AACL
Back to Top