public static function check($userId, $action, $asset = null)
	{
		// Sanitise inputs.
		$userId = (int) $userId;

		$action = strtolower(preg_replace('#[\s\-]+#', '.', trim($action)));
		$asset  = strtolower(preg_replace('#[\s\-]+#', '.', trim($asset)));

		// Default to the root asset node.
		if (empty($asset))
		{
			$asset = Asset::getRootId();
		}

		// Get the rules for the asset recursively to root if not already retrieved.
		if (empty(self::$assetRules[$asset]))
		{
			self::$assetRules[$asset] = self::getAssetRules($asset, true);
		}

		// Get all groups against which the user is mapped.
		$identities = self::getGroupsByUser($userId);
		array_unshift($identities, $userId * -1);

		return self::$assetRules[$asset]->allow($action, $identities);
	}
public static function check($userId, $action, $asset = null)
	{
		// Sanitise inputs.
		$userId = (int) $userId;

		$action = strtolower(preg_replace('#[\s\-]+#', '.', trim($action)));
		$asset  = strtolower(preg_replace('#[\s\-]+#', '.', trim($asset)));

		// Default to the root asset node.
		if (empty($asset))
		{
			$asset = Asset::getRootId();
		}

		// Get the rules for the asset recursively to root if not already retrieved.
		if (empty(self::$assetRules[$asset]))
		{
			self::$assetRules[$asset] = self::getAssetRules($asset, true);
		}

		// Get all groups against which the user is mapped.
		$identities = self::getGroupsByUser($userId);
		array_unshift($identities, $userId * -1);

		return self::$assetRules[$asset]->allow($action, $identities);
	}
public static function check ( $ userId , $ action , $ asset = null ) { // Sanitise inputs. $ userId = ( int ) $ userId ; $ action = strtolower ( preg_replace ( '#[\s\-]+#' , '.' , trim ( $ action ) ) ) ; $ asset = strtolower ( preg_replace ( '#[\s\-]+#' , '.' , trim ( $ asset ) ) ) ; // Default to the root asset node. if ( empty ( $ asset ) ) { $ asset = Asset :: getRootId ( ) ; } // Get the rules for the asset recursively to root if not already retrieved. if ( empty ( self :: $ assetRules [ $ asset ] ) ) { self :: $ assetRules [ $ asset ] = self :: getAssetRules ( $ asset , true ) ; } // Get all groups against which the user is mapped. $ identities = self :: getGroupsByUser ( $ userId ) ; array_unshift ( $ identities , $ userId * - 1 ) ; return self :: $ assetRules [ $ asset ] -> allow ( $ action , $ identities ) ; }
Method to check if a user is authorised to perform an action, optionally on an asset.

@param   integer  $userId  Id of the user for which to check authorisation.
@param   string   $action  The name of the action to authorise.
@param   mixed    $asset   Integer asset id or the name of the asset as a string.  Defaults to the global asset node.
@return  boolean  True if authorised.
Method to check if a user is authorised to perform an action optionally on an asset .