Created
January 5, 2011 13:48
-
-
Save icio/766327 to your computer and use it in GitHub Desktop.
include_subdirectories_in_path
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 | |
/** | |
* Add each directory within ./application to the include path so that each file | |
* is easily accessible. | |
*/ | |
function include_subdirectories_in_path() | |
{ | |
global $paths; | |
$paths = array('application'); | |
// Prepare the iterators | |
$dir = new RecursiveDirectoryIterator('application'); | |
$it = new RecursiveIteratorIterator($dir, RecursiveIteratorIterator::SELF_FIRST); | |
// Collect all of the directories | |
foreach ($it as $d) { | |
if ($d->isDir() && preg_match('/\\.svn/', $path = $d->getPathname()) == 0) { | |
$paths[] = $path; | |
} | |
} | |
// Collate into a path that can singly be added to the include path | |
$paths = implode(PATH_SEPARATOR, array_map('realpath', $paths)); | |
// Add to the include path | |
set_include_path(get_include_path() .PATH_SEPARATOR. $paths); | |
// Store the path components in the global variable | |
$paths = explode(PATH_SEPARATOR, get_include_path()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment