From 10b4a90501866b3be556ef2e0ef405ed0fb256fa Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Tue, 9 May 2017 21:40:35 +0300 Subject: [PATCH] Add useful functions to FileCollection class --- .../Framework/Collection/FileCollection.php | 40 ++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/system/src/Grav/Framework/Collection/FileCollection.php b/system/src/Grav/Framework/Collection/FileCollection.php index 68f969422..da9764448 100644 --- a/system/src/Grav/Framework/Collection/FileCollection.php +++ b/system/src/Grav/Framework/Collection/FileCollection.php @@ -25,6 +25,11 @@ class FileCollection extends AbstractLazyCollection const INCLUDE_FOLDERS = 2; const RECURSIVE = 4; + /** + * @var string + */ + protected $path; + /** * @var \RecursiveDirectoryIterator|RecursiveUniformResourceIterator */ @@ -56,25 +61,50 @@ class FileCollection extends AbstractLazyCollection */ public function __construct($path, $flags = null) { - $this->setIterator($path); + $this->path = $path; $this->flags = (int) ($flags ?: FileCollection::INCLUDE_FILES | FileCollection::INCLUDE_FOLDERS | FileCollection::RECURSIVE); + $this->setIterator(); $this->setFilter(); $this->setObjectBuilder(); $this->setNestingLimit(); } - public function setIterator($path) + /** + * @return string + */ + public function getPath() + { + return $this->path; + } + + /** + * @return int + */ + public function getFlags() + { + return $this->flags; + } + + /** + * @return int + */ + public function getNestingLimit() + { + return $this->nestingLimit; + } + + public function setIterator() { $iteratorFlags = \RecursiveDirectoryIterator::SKIP_DOTS + \FilesystemIterator::UNIX_PATHS + \FilesystemIterator::CURRENT_AS_SELF + \FilesystemIterator::FOLLOW_SYMLINKS; - if (strpos($path, '://')) { + if (strpos($this->path, '://')) { /** @var UniformResourceLocator $locator */ $locator = Grav::instance()['locator']; - $this->iterator = $locator->getRecursiveIterator($path, $iteratorFlags); + $this->iterator = $locator->getRecursiveIterator($this->path, $iteratorFlags); } else { - $this->iterator = new \RecursiveDirectoryIterator($path, $iteratorFlags); + $this->iterator = new \RecursiveDirectoryIterator($this->path, $iteratorFlags); } }