From ef593fa8d820f5ad8468b4f5f34c680923cdad15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Simon?= Date: Tue, 29 Jan 2013 19:42:39 +0100 Subject: [PATCH] [Finder] Fixed iterator keys --- .../Finder/Iterator/FilePathsIterator.php | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/Finder/Iterator/FilePathsIterator.php b/src/Symfony/Component/Finder/Iterator/FilePathsIterator.php index 283b041cb9e6..48634f27dad2 100644 --- a/src/Symfony/Component/Finder/Iterator/FilePathsIterator.php +++ b/src/Symfony/Component/Finder/Iterator/FilePathsIterator.php @@ -40,6 +40,11 @@ class FilePathsIterator extends \ArrayIterator */ private $subPathname; + /** + * @var SplFileInfo + */ + private $current; + /** * @param array $paths List of paths returned by shell command * @param string $baseDir Base dir for relative path building @@ -70,21 +75,27 @@ public function __call($name, array $arguments) */ public function current() { - return new SplFileInfo(parent::current(), $this->subPath, $this->subPathname); + return $this->current; + } + + /** + * @return string + */ + public function key() + { + return $this->current->getPathname(); } public function next() { parent::next(); - - $this->buildSubPath(); + $this->buildProperties(); } public function rewind() { parent::rewind(); - - $this->buildSubPath(); + $this->buildProperties(); } /** @@ -103,7 +114,7 @@ public function getSubPathname() return $this->subPathname; } - private function buildSubPath() + private function buildProperties() { $absolutePath = parent::current(); @@ -114,5 +125,7 @@ private function buildSubPath() } else { $this->subPath = $this->subPathname = ''; } + + $this->current = new SplFileInfo(parent::current(), $this->subPath, $this->subPathname); } }