dir.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  4. * @author Morris Jobke <hey@morrisjobke.de>
  5. * @author Robin Appelman <icewind@owncloud.com>
  6. *
  7. * @copyright Copyright (c) 2015, ownCloud, Inc.
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OC\Files\Stream;
  24. class Dir {
  25. private static $dirs = array();
  26. private $name;
  27. private $index;
  28. public function dir_opendir($path, $options) {
  29. $this->name = substr($path, strlen('fakedir://'));
  30. $this->index = 0;
  31. if (!isset(self::$dirs[$this->name])) {
  32. self::$dirs[$this->name] = array();
  33. }
  34. return true;
  35. }
  36. public function dir_readdir() {
  37. if ($this->index >= count(self::$dirs[$this->name])) {
  38. return false;
  39. }
  40. $filename = self::$dirs[$this->name][$this->index];
  41. $this->index++;
  42. return $filename;
  43. }
  44. public function dir_closedir() {
  45. $this->name = '';
  46. return true;
  47. }
  48. public function dir_rewinddir() {
  49. $this->index = 0;
  50. return true;
  51. }
  52. /**
  53. * @param string $path
  54. */
  55. public static function register($path, $content) {
  56. self::$dirs[$path] = $content;
  57. }
  58. }