diff options
Diffstat (limited to 'vendor/nelexa/zip/src/PhpZip/Util/Iterator')
-rw-r--r-- | vendor/nelexa/zip/src/PhpZip/Util/Iterator/IgnoreFilesFilterIterator.php | 61 | ||||
-rw-r--r-- | vendor/nelexa/zip/src/PhpZip/Util/Iterator/IgnoreFilesRecursiveFilterIterator.php | 70 |
2 files changed, 131 insertions, 0 deletions
diff --git a/vendor/nelexa/zip/src/PhpZip/Util/Iterator/IgnoreFilesFilterIterator.php b/vendor/nelexa/zip/src/PhpZip/Util/Iterator/IgnoreFilesFilterIterator.php new file mode 100644 index 0000000..40e8fe0 --- /dev/null +++ b/vendor/nelexa/zip/src/PhpZip/Util/Iterator/IgnoreFilesFilterIterator.php @@ -0,0 +1,61 @@ +<?php + +namespace PhpZip\Util\Iterator; + +use PhpZip\Util\StringUtil; + +/** + * Iterator for ignore files. + * + * @author Ne-Lexa alexey@nelexa.ru + * @license MIT + */ +class IgnoreFilesFilterIterator extends \FilterIterator +{ + /** + * Ignore list files + * + * @var array + */ + private $ignoreFiles = ['..']; + + /** + * @param \Iterator $iterator + * @param array $ignoreFiles + */ + public function __construct(\Iterator $iterator, array $ignoreFiles) + { + parent::__construct($iterator); + $this->ignoreFiles = array_merge($this->ignoreFiles, $ignoreFiles); + } + + /** + * Check whether the current element of the iterator is acceptable + * @link http://php.net/manual/en/filteriterator.accept.php + * @return bool true if the current element is acceptable, otherwise false. + * @since 5.1.0 + */ + public function accept() + { + /** + * @var \SplFileInfo $fileInfo + */ + $fileInfo = $this->current(); + $pathname = str_replace('\\', '/', $fileInfo->getPathname()); + foreach ($this->ignoreFiles as $ignoreFile) { + // handler dir and sub dir + if ($fileInfo->isDir() + && StringUtil::endsWith($ignoreFile, '/') + && StringUtil::endsWith($pathname, substr($ignoreFile, 0, -1)) + ) { + return false; + } + + // handler filename + if (StringUtil::endsWith($pathname, $ignoreFile)) { + return false; + } + } + return true; + } +} diff --git a/vendor/nelexa/zip/src/PhpZip/Util/Iterator/IgnoreFilesRecursiveFilterIterator.php b/vendor/nelexa/zip/src/PhpZip/Util/Iterator/IgnoreFilesRecursiveFilterIterator.php new file mode 100644 index 0000000..7781576 --- /dev/null +++ b/vendor/nelexa/zip/src/PhpZip/Util/Iterator/IgnoreFilesRecursiveFilterIterator.php @@ -0,0 +1,70 @@ +<?php + +namespace PhpZip\Util\Iterator; + +use PhpZip\Util\StringUtil; + +/** + * Recursive iterator for ignore files. + * + * @author Ne-Lexa alexey@nelexa.ru + * @license MIT + */ +class IgnoreFilesRecursiveFilterIterator extends \RecursiveFilterIterator +{ + + /** + * Ignore list files + * + * @var array + */ + private $ignoreFiles = ['..']; + + /** + * @param \RecursiveIterator $iterator + * @param array $ignoreFiles + */ + public function __construct(\RecursiveIterator $iterator, array $ignoreFiles) + { + parent::__construct($iterator); + $this->ignoreFiles = array_merge($this->ignoreFiles, $ignoreFiles); + } + + /** + * Check whether the current element of the iterator is acceptable + * @link http://php.net/manual/en/filteriterator.accept.php + * @return bool true if the current element is acceptable, otherwise false. + * @since 5.1.0 + */ + public function accept() + { + /** + * @var \SplFileInfo $fileInfo + */ + $fileInfo = $this->current(); + $pathname = str_replace('\\', '/', $fileInfo->getPathname()); + foreach ($this->ignoreFiles as $ignoreFile) { + // handler dir and sub dir + if ($fileInfo->isDir() + && $ignoreFile[strlen($ignoreFile) - 1] === '/' + && StringUtil::endsWith($pathname, substr($ignoreFile, 0, -1)) + ) { + return false; + } + + // handler filename + if (StringUtil::endsWith($pathname, $ignoreFile)) { + return false; + } + } + return true; + } + + /** + * @return IgnoreFilesRecursiveFilterIterator + */ + public function getChildren() + { + return new self($this->getInnerIterator()->getChildren(), $this->ignoreFiles); + } +} |