blob: 40e8fe0a93fe8b2a6d5ec64e59160ceea7846220 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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;
}
}
|