PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/system/php/spl/iterators/DirectoryIterator.php

https://gitlab.com/iranjith4/hhvm
PHP | 163 lines | 62 code | 14 blank | 87 comment | 9 complexity | 2524ba7398f5c5974b2e2f543c7f6eb7 MD5 | raw file
  1. <?php
  2. // This doc comment block generated by idl/sysdoc.php
  3. /**
  4. * ( excerpt from http://php.net/manual/en/class.directoryiterator.php )
  5. *
  6. * The DirectoryIterator class provides a simple interface for viewing the
  7. * contents of filesystem directories.
  8. *
  9. */
  10. class DirectoryIterator extends SplFileInfo implements SeekableIterator {
  11. private $dir;
  12. private $dirName;
  13. private $index;
  14. // This doc comment block generated by idl/sysdoc.php
  15. /**
  16. * ( excerpt from http://php.net/manual/en/directoryiterator.construct.php
  17. * )
  18. *
  19. * Constructs a new directory iterator from a path.
  20. *
  21. * @path mixed The path of the directory to traverse.
  22. */
  23. public function __construct($path) {
  24. if (empty($path)) {
  25. throw new RuntimeException("Directory name must not be empty.");
  26. }
  27. $this->dir = @opendir($path);
  28. if ($this->dir === false) {
  29. throw new UnexpectedValueException(
  30. "DirectoryIterator::__construct($path): failed to open dir"
  31. );
  32. }
  33. $this->dirName = rtrim($path, DIRECTORY_SEPARATOR);
  34. $this->index = 0;
  35. parent::__construct($this->readDir());
  36. }
  37. // This doc comment block generated by idl/sysdoc.php
  38. /**
  39. * ( excerpt from http://php.net/manual/en/directoryiterator.current.php )
  40. *
  41. * Get the current DirectoryIterator item.
  42. *
  43. * @return mixed The current DirectoryIterator item.
  44. */
  45. public function current() {
  46. return clone $this;
  47. }
  48. // This doc comment block generated by idl/sysdoc.php
  49. /**
  50. * ( excerpt from http://php.net/manual/en/directoryiterator.key.php )
  51. *
  52. * Get the key for the current DirectoryIterator item.
  53. *
  54. * @return mixed The key for the current DirectoryIterator item.
  55. */
  56. public function key() {
  57. return $this->index;
  58. }
  59. // This doc comment block generated by idl/sysdoc.php
  60. /**
  61. * ( excerpt from http://php.net/manual/en/directoryiterator.next.php )
  62. *
  63. * Move forward to the next DirectoryIterator item.
  64. *
  65. * @return mixed No value is returned.
  66. */
  67. public function next() {
  68. $this->setPathname($this->readDir());
  69. $this->index++;
  70. }
  71. // This doc comment block generated by idl/sysdoc.php
  72. /**
  73. * ( excerpt from http://php.net/manual/en/directoryiterator.rewind.php )
  74. *
  75. * Rewind the DirectoryIterator back to the start.
  76. *
  77. * @return mixed No value is returned.
  78. */
  79. public function rewind() {
  80. rewinddir($this->dir);
  81. $this->index = -1;
  82. $this->next();
  83. }
  84. // This doc comment block generated by idl/sysdoc.php
  85. /**
  86. * ( excerpt from http://php.net/manual/en/directoryiterator.seek.php )
  87. *
  88. * Seek to a given position in the DirectoryIterator.
  89. *
  90. * @position mixed The zero-based numeric position to seek to.
  91. *
  92. * @return mixed No value is returned.
  93. */
  94. public function seek($position) {
  95. $this->rewind();
  96. for ($i = $this->index; $i < $position; $i++) {
  97. $this->next();
  98. }
  99. }
  100. // This doc comment block generated by idl/sysdoc.php
  101. /**
  102. * ( excerpt from http://php.net/manual/en/directoryiterator.tostring.php )
  103. *
  104. * Get the file name of the current DirectoryIterator item.
  105. *
  106. * @return mixed Returns the file name of the current
  107. * DirectoryIterator item.
  108. */
  109. public function __toString() {
  110. return $this->getFilename();
  111. }
  112. // This doc comment block generated by idl/sysdoc.php
  113. /**
  114. * ( excerpt from http://php.net/manual/en/directoryiterator.valid.php )
  115. *
  116. * Check whether current DirectoryIterator position is a valid file.
  117. *
  118. * @return mixed Returns TRUE if the position is valid, otherwise
  119. * FALSE
  120. */
  121. public function valid() {
  122. return $this->getPathname() !== false;
  123. }
  124. // This doc comment block generated by idl/sysdoc.php
  125. /**
  126. * ( excerpt from http://php.net/manual/en/directoryiterator.isdot.php )
  127. *
  128. * Determines if the current DirectoryIterator item is a directory and
  129. * either . or ...
  130. *
  131. * @return mixed TRUE if the entry is . or .., otherwise FALSE
  132. */
  133. public function isDot() {
  134. return $this->getPathname() !== false && (
  135. $this->getFilename() == '.' || $this->getFilename() == '..'
  136. );
  137. }
  138. private function readDir() {
  139. // hh_readdir will set $this->dirName if necessary
  140. $file_name = $this->hh_readdir();
  141. if ($file_name === false) {
  142. return false;
  143. } else {
  144. return $this->dirName.DIRECTORY_SEPARATOR.$file_name;
  145. }
  146. }
  147. <<__Native>>
  148. private function hh_readdir(): mixed;
  149. }