Skip to content

Instantly share code, notes, and snippets.

@icio icio/gist:766327

Created Jan 5, 2011
Embed
What would you like to do?
include_subdirectories_in_path
<?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
You can’t perform that action at this time.