1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace Symfony\Component\Finder\Iterator;
13:
14: use Symfony\Component\Finder\SplFileInfo;
15:
16: 17: 18: 19: 20:
21: class FilePathsIterator extends \ArrayIterator
22: {
23: 24: 25:
26: private $baseDir;
27:
28: 29: 30:
31: private $baseDirLength;
32:
33: 34: 35:
36: private $subPath;
37:
38: 39: 40:
41: private $subPathname;
42:
43: 44: 45:
46: private $current;
47:
48: 49: 50: 51:
52: public function __construct(array $paths, $baseDir)
53: {
54: $this->baseDir = $baseDir;
55: $this->baseDirLength = strlen($baseDir);
56:
57: parent::__construct($paths);
58: }
59:
60: 61: 62: 63: 64: 65:
66: public function __call($name, array $arguments)
67: {
68: return call_user_func_array(array($this->current(), $name), $arguments);
69: }
70:
71: 72: 73: 74: 75:
76: public function current()
77: {
78: return $this->current;
79: }
80:
81: 82: 83:
84: public function key()
85: {
86: return $this->current->getPathname();
87: }
88:
89: public function next()
90: {
91: parent::next();
92: $this->buildProperties();
93: }
94:
95: public function rewind()
96: {
97: parent::rewind();
98: $this->buildProperties();
99: }
100:
101: 102: 103:
104: public function getSubPath()
105: {
106: return $this->subPath;
107: }
108:
109: 110: 111:
112: public function getSubPathname()
113: {
114: return $this->subPathname;
115: }
116:
117: private function buildProperties()
118: {
119: $absolutePath = parent::current();
120:
121: if ($this->baseDir === substr($absolutePath, 0, $this->baseDirLength)) {
122: $this->subPathname = ltrim(substr($absolutePath, $this->baseDirLength), '/\\');
123: $dir = dirname($this->subPathname);
124: $this->subPath = '.' === $dir ? '' : $dir;
125: } else {
126: $this->subPath = $this->subPathname = '';
127: }
128:
129: $this->current = new SplFileInfo(parent::current(), $this->subPath, $this->subPathname);
130: }
131: }
132: