Skip to content

Instantly share code, notes, and snippets.

@icio
Created January 5, 2011 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save icio/766327 to your computer and use it in GitHub Desktop.
Save icio/766327 to your computer and use it in GitHub Desktop.
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