Created
June 14, 2010 21:09
-
-
Save katanacrimson/438302 to your computer and use it in GitHub Desktop.
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 | |
// Define the location of where we are keeping all relevant files :) | |
define('FAILNET_ROOT', '/home/obsidian/Code/failnet_dev'); | |
// (relative to the root dir specified) what directories do we want to search in? | |
$dirs = array( | |
'', | |
'Core', | |
'Cron', | |
'Event', | |
'Lib', | |
'Node', | |
'Plugin' | |
); | |
// Is there anything specific we want to exclude? | |
$exclude = array( | |
'Failnet\\Bootstrap', | |
'Failnet\\Constants', | |
'Failnet\\Functions', | |
); | |
// and now we scan... | |
foreach($dirs as $dir) | |
{ | |
foreach(getNamespaces(FAILNET_ROOT . '/Includes/' . ucfirst($dir), 'Includes/') as $file) | |
{ | |
if(!in_array($file, $exclude)) | |
echo $file . PHP_EOL; | |
} | |
} | |
/** | |
* Scan a directory for files that we want to extract the relevant namespacing info for | |
* @param string $path - The path to scan | |
* @param string $strip - Anything extra to strip out of the path when generating the namespace | |
* @param string $prefix - A namespace prefix to use, if we need one | |
* @return array - An array of class names to autoload. | |
*/ | |
function getNamespaces($path, $strip = '', $prefix = '') | |
{ | |
$files = scandir($path); | |
foreach($files as $file) | |
{ | |
if($file[0] == '.' || substr(strrchr($file, '.'), 1) != 'php') | |
continue; | |
$prefix = (!$prefix) ? 'Failnet\\' . str_replace('/', '\\', substr($path, strlen(FAILNET_ROOT . $strip) + 1)) : $prefix; | |
$return[] = $prefix . (substr($prefix, -1, 1) != '\\' ? '\\' : '') . ucfirst(substr($file, 0, strrpos($file, '.'))); | |
} | |
return $return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment