From 645ffd9ed18a00000a5f7aa70cb760ff48ea8cb5 Mon Sep 17 00:00:00 2001 From: Alexander Demidov Date: Mon, 21 Oct 2013 15:51:24 +0400 Subject: [PATCH] Add support symlink into Autoload. --- Load.php | 1 + util/AsciiSortedIterator.php | 18 ++++++++++++++++++ util/AutoloadBuilder.php | 6 +++--- 3 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 util/AsciiSortedIterator.php diff --git a/Load.php b/Load.php index 9312873..0647dfa 100644 --- a/Load.php +++ b/Load.php @@ -79,6 +79,7 @@ class Load if (!self::$builder) { require_once(PATH . '/lib/core/util/AutoloadBuilder.php'); + require_once(PATH . '/lib/core/util/AsciiSortedIterator.php'); self::$builder = new AutoloadBuilder(self::$file, $scan, $exclude); } self::$builder->build(); diff --git a/util/AsciiSortedIterator.php b/util/AsciiSortedIterator.php new file mode 100644 index 0000000..fbe42e2 --- /dev/null +++ b/util/AsciiSortedIterator.php @@ -0,0 +1,18 @@ +insert($item); + } + } + public function compare($b,$a) + { + /** + * @var $a SplFileInfo + * @var $b SplFileInfo + */ + return strcmp($a->getPath() . DIRECTORY_SEPARATOR . $a->getFileName(), $b->getPath() . DIRECTORY_SEPARATOR . $b->getFileName()); + } +} \ No newline at end of file diff --git a/util/AutoloadBuilder.php b/util/AutoloadBuilder.php index 1f9bd10..4f27ece 100644 --- a/util/AutoloadBuilder.php +++ b/util/AutoloadBuilder.php @@ -38,10 +38,10 @@ class AutoloadBuilder $classes = array(); foreach ($this->dirs as $dir) { $iterator = new RecursiveIteratorIterator( - new RecursiveDirectoryIterator($dir), + new RecursiveDirectoryIterator($dir, FilesystemIterator::FOLLOW_SYMLINKS | FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::LEAVES_ONLY ); - + $iterator = new AsciiSortedIterator($iterator); foreach ($iterator as $file) { /** * @var SplFileInfo $file @@ -58,7 +58,7 @@ class AutoloadBuilder $content = file_get_contents($file->getRealPath()); $matches = array(); - $relative_path = substr($file->getRealPath(), strlen(PATH)); + $relative_path = substr($file->getPath() . DIRECTORY_SEPARATOR . $file->getFilename(), strlen(PATH)); if (preg_match_all($this->regex, $content, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) {