开发者

Zend Autoloader - Load files from directory

I was wondering if there's any way to use Zend Autoloader to load all files from specific directory and subdirectories?

I'm trying t开发者_如何学Co include other libraries beside Zend such as JSTree.


Update

Just found SPL's RecursiveDirectoryIterator. That may be a better option.


There isn't anything Zend Framework specific, but you could take a look at PHP SPL's DirectoryIterator.

You could use it like this: (untested)

class My_DirectoryIterator extends DirectoryIterator
{
    /**
     * Load every file in the directory and it's sub directories
     * It might be a good idea to put a limit on subdirectory iteration so you don't disappear down a black hole...
     * @return void
     */
    public function loadRecursive()
    {
        foreach ($this as $file) {
            if ($file->isDir() || $file->isLink()) {
                $iterator = new self($file->getPathName());
                $iterator->loadRecursive();
            } elseif ($file->isFile()) {
                // Might want to check for .php extension or something first
                require_once $file->getPathName();
            }
        }
    }
}

// Load them all
$iterator = new My_DirectoryIterator('/path/to/parent/directory');
$iterator->loadRecursive();


If those libs are PSR-0 compilant, you can use

Zend_Loader_Autoloader::getInstance()->setFallbackAutoloader(true);

That will make Zend load any unknown classes (looking for Some_Class in Some/Class.php).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜