DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Get Access Via Annotatio

02.22.2010
| 2240 views |
  • submit to reddit
        // Get access via annotation

Faça voce mesmo vosso framework

<?php 
/**
* @access:public
*/
class MyController
{
	
	/**
	* Widget box in portal
	* @access:public
	*/
	public function widget()
	{
		echo "widget";
	}
	
	//Not has annotation? ok...this is public by default
	function foo()
	{
		echo "Foo";
	}
	
	/**
	 * Login requerided
	 * @access:private
	 */
	public function boxWidget()
	{
		echo "List my personal";
	}
}


function getAccess($className, $methodName=false)
{
	if ($methodName){
		$reflector  = new ReflectionMethod($className, $methodName);
		$docblock = strtolower($reflector->getDocComment());
	}else{
		$class = new ReflectionClass($className);
		$docblock = strtolower($class->getDocComment());
	}
    if (preg_match('/\@access:(.*$)/m', $docblock, $matches)) {
		$access = trim($matches[1]);
    }
    return $access;
}


$controller = 'MyController';

echo "only class:";
echo getAccess($controller);
 ?>
<hr>
<?php
echo "boxWidget:";
$action = 'boxWidget';
echo getAccess($controller, $action);
?>

<hr>
<?php
echo "widget:";
$action = 'widget';
echo getAccess($controller, $action);
?>
<hr>
<?php
echo "foo:";
$action = 'foo';
echo getAccess($controller, $action);
?>