Created
October 7, 2011 09:46
-
-
Save pentium10/1269919 to your computer and use it in GitHub Desktop.
Implemented support for method 'actions' of controllers
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 | |
| // SEE | |
| // http://code.google.com/p/yii-rights/issues/detail?id=41&q=actions | |
| /** | |
| * Returns all the controllers and their actions. | |
| * @param array $items the controllers and actions. | |
| */ | |
| public function getControllerActions($items=null) { | |
| if ($items === null) | |
| $items = $this->getAllControllers(); | |
| foreach ($items['controllers'] as $controllerName => $controller) { | |
| $actions = array(); | |
| $pi = pathinfo($controller['path']); | |
| $className = $pi['filename']; | |
| // check if this class is loaded | |
| if (!class_exists($className, $autoload = false)) { | |
| include($controller['path']); | |
| } | |
| try { | |
| if (class_exists($className)) { | |
| $o = new $className($id = time(), $module = ''); | |
| $objActions = $o->actions(); | |
| if (!empty($objActions)) { | |
| foreach ($objActions as $name=>$class) { | |
| $actions[strtolower($name)] = array( | |
| 'name' => $name, | |
| 'line' => 0 | |
| ); | |
| } | |
| } | |
| } | |
| } catch (Exception $e) { | |
| // ignore any exception that might happened | |
| } | |
| $file = fopen($controller['path'], 'r'); | |
| $lineNumber = 0; | |
| while (feof($file) === false) { | |
| ++$lineNumber; | |
| $line = fgets($file); | |
| preg_match('/public[ \t]+function[ \t]+action([A-Z]{1}[a-zA-Z0-9]+)[ \t]*\(/', $line, $matches); | |
| if ($matches !== array()) { | |
| $name = $matches[1]; | |
| $actions[strtolower($name)] = array( | |
| 'name' => $name, | |
| 'line' => $lineNumber | |
| ); | |
| } | |
| } | |
| $items['controllers'][$controllerName]['actions'] = $actions; | |
| } | |
| foreach ($items['modules'] as $moduleName => $module) | |
| $items['modules'][$moduleName] = $this->getControllerActions($module); | |
| return $items; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment