TYPO3  7.6
FilePathsIterator.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
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 Symfony\Component\Finder\Iterator;
13 
15 
21 class FilePathsIterator extends \ArrayIterator
22 {
26  private $baseDir;
27 
31  private $baseDirLength;
32 
36  private $subPath;
37 
41  private $subPathname;
42 
46  private $current;
47 
52  public function __construct(array $paths, $baseDir)
53  {
54  $this->baseDir = $baseDir;
55  $this->baseDirLength = strlen($baseDir);
56 
57  parent::__construct($paths);
58  }
59 
66  public function __call($name, array $arguments)
67  {
68  return call_user_func_array(array($this->current(), $name), $arguments);
69  }
70 
76  public function current()
77  {
78  return $this->current;
79  }
80 
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 
104  public function getSubPath()
105  {
106  return $this->subPath;
107  }
108 
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 }