|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the webmozart/glob package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Bernhard Schussek <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Webmozart\Glob\Iterator; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Recursive directory iterator that is working during recursive iteration. |
|
16
|
|
|
* |
|
17
|
|
|
* Recursive iteration is broken on PHP < 5.5.23 and on PHP 5.6 < 5.6.7. |
|
18
|
|
|
* |
|
19
|
|
|
* @since 1.0 |
|
20
|
|
|
* @since 3.0 Removed support for seek(), added \RecursiveDirectoryIterator |
|
21
|
|
|
* base class, adapted API to match \RecursiveDirectoryIterator |
|
22
|
|
|
* @since 3.1 Slashes are normalized to forward slashes on Windows |
|
23
|
|
|
* |
|
24
|
|
|
* @author Bernhard Schussek <[email protected]> |
|
25
|
|
|
*/ |
|
26
|
|
|
class RecursiveDirectoryIterator extends \RecursiveDirectoryIterator |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @var bool |
|
30
|
|
|
*/ |
|
31
|
|
|
private $normalizeKey; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var bool |
|
35
|
|
|
*/ |
|
36
|
|
|
private $normalizeCurrent; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* {@inheritdoc} |
|
40
|
|
|
*/ |
|
41
|
18 |
|
public function __construct($path, $flags = 0) |
|
42
|
|
|
{ |
|
43
|
18 |
|
parent::__construct($path, $flags); |
|
44
|
|
|
|
|
45
|
|
|
// Normalize slashes on Windows |
|
46
|
17 |
|
$this->normalizeKey = '\\' === DIRECTORY_SEPARATOR && !($flags & self::KEY_AS_FILENAME); |
|
47
|
17 |
|
$this->normalizeCurrent = '\\' === DIRECTORY_SEPARATOR && ($flags & self::CURRENT_AS_PATHNAME); |
|
48
|
17 |
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* {@inheritdoc} |
|
52
|
|
|
*/ |
|
53
|
10 |
|
public function getChildren() |
|
54
|
|
|
{ |
|
55
|
10 |
|
return new static($this->getPathname(), $this->getFlags()); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* {@inheritdoc} |
|
60
|
|
|
*/ |
|
61
|
17 |
|
public function key() |
|
62
|
|
|
{ |
|
63
|
17 |
|
$key = parent::key(); |
|
64
|
|
|
|
|
65
|
17 |
|
if ($this->normalizeKey) { |
|
66
|
|
|
$key = str_replace('\\', '/', $key); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
17 |
|
return $key; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* {@inheritdoc} |
|
74
|
|
|
*/ |
|
75
|
17 |
|
public function current() |
|
76
|
|
|
{ |
|
77
|
17 |
|
$current = parent::current(); |
|
78
|
|
|
|
|
79
|
17 |
|
if ($this->normalizeCurrent) { |
|
80
|
|
|
$current = str_replace('\\', '/', $current); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
17 |
|
return $current; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|