public static function addDirectory($directory, $extensionToFind = '.php', $bypassDirectories = '')
	{
        self::register();

		$dir = new SplFileInfo($directory);
		if (!$dir->isDir()) {
		    throw new ApplicationContextException('Cannot add directory to ClassLoader, directory does not exist: ' . $directory);
        }

        if (!is_array($bypassDirectories)) {
            $bypassDirectories = explode(',', $bypassDirectories);
        }

		$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::SELF_FIRST);
		foreach ($objects as $name => $object) {
		    if (self::isVcsFile($name)) {
		        continue;
            }

            $tmpPath = explode(DIRECTORY_SEPARATOR, ltrim(str_replace($directory, '', $name), DIRECTORY_SEPARATOR));
            $rootNode = array_shift($tmpPath);
            if (in_array($rootNode, $bypassDirectories)) {
                continue;
            }

			if (!$object->isFile()) {
			    continue;
            }

            $extension = substr($object->getFilename(), strlen($extensionToFind)*-1);
            if ($extension !== $extensionToFind) {
                continue;
            }

			self::addFile($object, $extensionToFind);
		}
	}
public static function addDirectory($directory, $extensionToFind = '.php', $bypassDirectories = '')
	{
        self::register();

		$dir = new SplFileInfo($directory);
		if (!$dir->isDir()) {
		    throw new ApplicationContextException('Cannot add directory to ClassLoader, directory does not exist: ' . $directory);
        }

        if (!is_array($bypassDirectories)) {
            $bypassDirectories = explode(',', $bypassDirectories);
        }

		$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::SELF_FIRST);
		foreach ($objects as $name => $object) {
		    if (self::isVcsFile($name)) {
		        continue;
            }

            $tmpPath = explode(DIRECTORY_SEPARATOR, ltrim(str_replace($directory, '', $name), DIRECTORY_SEPARATOR));
            $rootNode = array_shift($tmpPath);
            if (in_array($rootNode, $bypassDirectories)) {
                continue;
            }

			if (!$object->isFile()) {
			    continue;
            }

            $extension = substr($object->getFilename(), strlen($extensionToFind)*-1);
            if ($extension !== $extensionToFind) {
                continue;
            }

			self::addFile($object, $extensionToFind);
		}
	}
public static function addDirectory ( $ directory , $ extensionToFind = '.php' , $ bypassDirectories = '' ) { self :: register ( ) ; $ dir = new SplFileInfo ( $ directory ) ; if ( ! $ dir -> isDir ( ) ) { throw new ApplicationContextException ( 'Cannot add directory to ClassLoader, directory does not exist: ' . $ directory ) ; } if ( ! is_array ( $ bypassDirectories ) ) { $ bypassDirectories = explode ( ',' , $ bypassDirectories ) ; } $ objects = new RecursiveIteratorIterator ( new RecursiveDirectoryIterator ( $ dir ) , RecursiveIteratorIterator :: SELF_FIRST ) ; foreach ( $ objects as $ name => $ object ) { if ( self :: isVcsFile ( $ name ) ) { continue ; } $ tmpPath = explode ( DIRECTORY_SEPARATOR , ltrim ( str_replace ( $ directory , '' , $ name ) , DIRECTORY_SEPARATOR ) ) ; $ rootNode = array_shift ( $ tmpPath ) ; if ( in_array ( $ rootNode , $ bypassDirectories ) ) { continue ; } if ( ! $ object -> isFile ( ) ) { continue ; } $ extension = substr ( $ object -> getFilename ( ) , strlen ( $ extensionToFind ) * - 1 ) ; if ( $ extension !== $ extensionToFind ) { continue ; } self :: addFile ( $ object , $ extensionToFind ) ; } }
Scans a directory recursively for all files with
a particular extension and will add any classes
it finds with the full path.

@param string $directory
@param string $extensionToFind
@param string $bypassDirectories

@throws ApplicationContextException

@return void
Scans a directory recursively for all files with a particular extension and will add any classes it finds with the full path .