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
Get Access Via Annotatio
// 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);
?>





