Last active
August 29, 2015 14:11
-
-
Save gnugat/3f842a512a48eeaac346 to your computer and use it in GitHub Desktop.
Nano Nomo Spaco
This file contains 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 | |
if (!isset($argv[1])) { | |
die('Usage: '.$argv[0].' <path>'); | |
} | |
$path = $argv[1]; | |
$fqcns = array(); | |
$allFiles = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)); | |
$phpFiles = new RegexIterator($allFiles, '/\.php$/'); | |
foreach ($phpFiles as $phpFile) { | |
$content = file_get_contents($phpFile->getRealPath()); | |
$tokens = token_get_all($content); | |
$namespace = ''; | |
for ($index = 0; isset($tokens[$index]); $index++) { | |
if (!isset($tokens[$index][0])) { | |
continue; | |
} | |
if (T_NAMESPACE === $tokens[$index][0]) { | |
$index += 2; // Skip namespace keyword and whitespace | |
while (isset($tokens[$index]) && is_array($tokens[$index])) { | |
$namespace .= $tokens[$index++][1]; | |
} | |
} | |
if (T_CLASS === $tokens[$index][0]) { | |
$index += 2; // Skip class keyword and whitespace | |
$fqcns[] = $namespace.'\\'.$tokens[$index][1]; | |
} | |
} | |
} | |
print_r($fqcns); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment