Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $allFiles = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(\Yii::app()->getBasePath()));
- $phpFiles = new \RegexIterator($allFiles, '/\.php$/');
- $res = [];
- /** @var SplFileInfo $phpFile */
- foreach ($phpFiles as $phpFile) {
- $content = file_get_contents($phpFile->getRealPath());
- $tokens = token_get_all($content);
- $className = '';
- for ($index = 0; isset($tokens[$index]); $index++) {
- if (!isset($tokens[$index][0])) {
- continue;
- }
- if (T_CLASS === $tokens[$index][0]) {
- $index += 2; // Skip class keyword and whitespace
- $className = $tokens[$index][1];
- }
- if (T_FUNCTION === $tokens[$index][0]) {
- $index += 2; // Skip class keyword and whitespace
- $mName = $tokens[$index][1];
- if (substr($mName, 0, 2) !== 'on') {
- continue;
- }
- if(!array_key_exists($className,$res)){
- $res[$className] = [
- 'path' => $phpFile->getPathname(),
- 'events' => [],
- ];
- }
- $res[$className]['events'][] = $mName;
- }
- }
- }
- dd($res);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement