ILIAS  release_8 Revision v8.24
RecursiveDirectoryIterator.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
6
9use ReturnTypeWillChange;
10
11/******************************************************************************
12 *
13 * This file is part of ILIAS, a powerful learning management system.
14 *
15 * ILIAS is licensed with the GPL-3.0, you should have received a copy
16 * of said license along with the source code.
17 *
18 * If this is not the case or you just want to try ILIAS, you'll find
19 * us at:
20 * https://www.ilias.de
21 * https://github.com/ILIAS-eLearning
22 *
23 *****************************************************************************/
24
30class RecursiveDirectoryIterator implements \RecursiveIterator
31{
33 protected string $dir;
35 protected array $files = [];
36
42 public function __construct(Filesystem $filesystem, string $dir)
43 {
44 $this->filesystem = $filesystem;
45 $this->dir = $dir;
46 }
47
51 public function key()
52 {
53 return key($this->files);
54 }
55
59 public function next(): void
60 {
61 next($this->files);
62 }
63
67 public function current(): Metadata
68 {
69 return current($this->files);
70 }
71
75 public function valid(): bool
76 {
77 return current($this->files) instanceof Metadata;
78 }
79
83 public function rewind(): void
84 {
85 $contents = $this->filesystem->listContents($this->dir, false);
86 $this->files = array_combine(array_map(static fn (Metadata $metadata): string => $metadata->getPath(), $contents), $contents);
87 }
88
92 public function hasChildren(): bool
93 {
94 return $this->current()->isDir();
95 }
96
101 {
102 return new self($this->filesystem, $this->current()->getPath());
103 }
104}
getPath()
The path to the file or directory.
Definition: Metadata.php:56
__construct(Filesystem $filesystem, string $dir)
RecursiveDirectoryIterator constructor.
Interface Filesystem.
Definition: Filesystem.php:40
Class FlySystemFileAccessTest \Provider\FlySystem @runTestsInSeparateProcesses @preserveGlobalState d...
Class ChatMainBarProvider \MainMenu\Provider.