Created
October 25, 2011 12:56
-
-
Save zircote/1312647 to your computer and use it in GitHub Desktop.
Introspection for ACL resource->role mapping.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class ErrorController extends Zend_Controller_Action | |
| { | |
| /** | |
| * @aclRole annonymous | |
| * @aclRole admin | |
| */ | |
| public function errorAction() | |
| { | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Parses all Controller and generates the ACL lists examines the @aclRole | |
| * annotation for declared roles. | |
| * | |
| * @author zircote | |
| * | |
| */ | |
| class PinCrowd_Application_Acl_Parser | |
| { | |
| /** | |
| * | |
| * | |
| * @var Zend_Controller_Front | |
| */ | |
| protected $_frontController; | |
| public function __construct(Zend_Controller_Front $frontController) | |
| { | |
| $this->_frontController = $frontController; | |
| } | |
| /** | |
| * | |
| * | |
| * @return array | |
| */ | |
| public function run() | |
| { | |
| $files = array(); | |
| foreach ($this->_frontController->getControllerDirectory() as $module => $directory) { | |
| $dir = new DirectoryIterator($directory); | |
| foreach ($dir as $fileInfo) { | |
| if(!$fileInfo->isDot()){ | |
| if($module != 'default'){ | |
| $prefix = ucfirst($module) . '_' ; | |
| } else { | |
| $prefix = null; | |
| } | |
| $class = str_replace('.php','',$prefix . $fileInfo->getFileName()); | |
| require_once ($directory . DIRECTORY_SEPARATOR . $fileInfo->getFileName()); | |
| $controller = strtolower(str_replace('Controller', '', str_replace('.php','',$fileInfo->getFileName()))); | |
| $files[$module][$controller] = $this->_reflect($class); | |
| } | |
| } | |
| } | |
| return $files; | |
| } | |
| /** | |
| * | |
| * | |
| * @param string $class (classname for introspection) | |
| */ | |
| protected function _reflect($class) | |
| { | |
| $response = array(); | |
| $reflect = new Zend_Reflection_Class($class); | |
| $methods = $reflect->getMethods(ReflectionMethod::IS_PUBLIC); | |
| /* @var $method Zend_Reflection_Method */ | |
| foreach ($methods as $method) { | |
| if(substr($method->name,-6) == 'Action'){ | |
| $roles = array(); | |
| if($method->getDocComment()){ | |
| $docblock = new Zend_Reflection_Docblock($method->getDocComment()); | |
| /* @var $tag Zend_Reflection_Docblock_Tag */ | |
| foreach ($docblock->getTags('aclRole') as $tag) { | |
| $roles[] = $tag->getDescription(); | |
| } | |
| } else { | |
| $roles[] = 'admin'; | |
| } | |
| $response[substr($method->name,0,-6)] = $roles; | |
| } | |
| } | |
| return $response; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Array | |
| ( | |
| [default] => Array | |
| ( | |
| [about] => Array | |
| ( | |
| [index] => Array | |
| ( | |
| [0] => annonymous | |
| ) | |
| ) | |
| [contact] => Array | |
| ( | |
| [index] => Array | |
| ( | |
| [0] => annonymous | |
| ) | |
| ) | |
| [error] => Array | |
| ( | |
| [error] => Array | |
| ( | |
| [0] => annonymous | |
| [1] => admin | |
| ) | |
| ) | |
| [index] => Array | |
| ( | |
| [index] => Array | |
| ( | |
| [0] => annonymous | |
| ) | |
| ) | |
| ) | |
| [alley] => Array | |
| ( | |
| [shoes] => Array | |
| ( | |
| [index] => Array | |
| ( | |
| [0] => admin | |
| ) | |
| ) | |
| ) | |
| [auth] => Array | |
| ( | |
| [account] => Array | |
| ( | |
| [index] => Array | |
| ( | |
| [0] => admin | |
| ) | |
| ) | |
| [index] => Array | |
| ( | |
| [index] => Array | |
| ( | |
| [0] => admin | |
| ) | |
| ) | |
| [login] => Array | |
| ( | |
| [index] => Array | |
| ( | |
| [0] => admin | |
| ) | |
| ) | |
| [logout] => Array | |
| ( | |
| [index] => Array | |
| ( | |
| [0] => admin | |
| ) | |
| ) | |
| [password] => Array | |
| ( | |
| [index] => Array | |
| ( | |
| [0] => admin | |
| ) | |
| ) | |
| [register] => Array | |
| ( | |
| [index] => Array | |
| ( | |
| [0] => admin | |
| ) | |
| ) | |
| ) | |
| [company] => Array | |
| ( | |
| [index] => Array | |
| ( | |
| [index] => Array | |
| ( | |
| [0] => admin | |
| ) | |
| ) | |
| [info] => Array | |
| ( | |
| [index] => Array | |
| ( | |
| [0] => admin | |
| ) | |
| ) | |
| [signup] => Array | |
| ( | |
| [index] => Array | |
| ( | |
| [0] => admin | |
| ) | |
| ) | |
| ) | |
| [game] => Array | |
| ( | |
| [lane] => Array | |
| ( | |
| [index] => Array | |
| ( | |
| [0] => admin | |
| ) | |
| ) | |
| [match] => Array | |
| ( | |
| [index] => Array | |
| ( | |
| [0] => admin | |
| ) | |
| ) | |
| [overview] => Array | |
| ( | |
| [index] => Array | |
| ( | |
| [0] => admin | |
| ) | |
| ) | |
| ) | |
| [player] => Array | |
| ( | |
| [ranking] => Array | |
| ( | |
| [index] => Array | |
| ( | |
| [0] => admin | |
| ) | |
| ) | |
| [statistics] => Array | |
| ( | |
| [index] => Array | |
| ( | |
| [0] => admin | |
| ) | |
| ) | |
| ) | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment