Hoa central
Directory.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\Iterator\Recursive;
38 
47 class Directory extends \RecursiveDirectoryIterator
48 {
54  protected $_splFileInfoClass = null;
55 
61  protected $_relativePath = 0;
62 
68  private static $_handlePath = null;
69 
70 
71 
81  public function __construct($path, $flags = null, $splFileInfoClass = null)
82  {
83  if (null === $flags) {
84  parent::__construct($path);
85  } else {
86  parent::__construct($path, $flags);
87  }
88 
89  if (null !== self::$_handlePath) {
90  $this->_relativePath = self::$_handlePath;
91  self::$_handlePath = null;
92  } else {
93  $this->_relativePath = $path;
94  }
95 
96  $this->setSplFileInfoClass($splFileInfoClass);
97 
98  return;
99  }
100 
107  public function current()
108  {
109  $out = parent::current();
110 
111  if (null !== $this->_splFileInfoClass &&
112  $out instanceof \SplFileInfo) {
113  $out->setInfoClass($this->_splFileInfoClass);
114  $out = $out->getFileInfo();
115 
116  if ($out instanceof \Hoa\Iterator\SplFileInfo) {
117  $out->setRelativePath($this->getRelativePath());
118  }
119  }
120 
121  return $out;
122  }
123 
130  public function getChildren()
131  {
132  self::$_handlePath = $this->getRelativePath();
133  $out = parent::getChildren();
134 
135  if ($out instanceof \RecursiveDirectoryIterator) {
136  $out->setSplFileInfoClass($this->_splFileInfoClass);
137  }
138 
139  return $out;
140  }
141 
148  public function setSplFileInfoClass($splFileInfoClass)
149  {
150  $this->_splFileInfoClass = $splFileInfoClass;
151 
152  return;
153  }
154 
160  public function getRelativePath()
161  {
162  return $this->_relativePath;
163  }
164 }
setSplFileInfoClass($splFileInfoClass)
Definition: Directory.php:148
__construct($path, $flags=null, $splFileInfoClass=null)
Definition: Directory.php:81