Skip to content

Instantly share code, notes, and snippets.

@katanacrimson
Created June 14, 2010 21:09
Show Gist options
  • Save katanacrimson/438302 to your computer and use it in GitHub Desktop.
Save katanacrimson/438302 to your computer and use it in GitHub Desktop.
<?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