ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
RecursiveDirectoryIterator.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25
31class RecursiveDirectoryIterator implements \RecursiveIterator
32{
34 protected array $files = [];
35
39 public function __construct(private Filesystem $filesystem, protected string $dir)
40 {
41 }
42
46 public function key(): int|string
47 {
48 return key($this->files);
49 }
50
54 public function next(): void
55 {
56 next($this->files);
57 }
58
62 public function current(): bool|Metadata
63 {
64 return current($this->files);
65 }
66
70 public function valid(): bool
71 {
72 return current($this->files) instanceof Metadata;
73 }
74
78 public function rewind(): void
79 {
80 $contents = $this->filesystem->listContents($this->dir, false);
81 $this->files = array_combine(
82 array_map(static fn(Metadata $metadata): string => $metadata->getPath(), $contents),
83 $contents
84 );
85 }
86
90 public function hasChildren(): bool
91 {
92 return $this->current()->isDir();
93 }
94
99 {
100 return new self($this->filesystem, $this->current()->getPath());
101 }
102}
This class holds all default metadata send by the filesystem adapters.
Definition: Metadata.php:33
getPath()
The path to the file or directory.
Definition: Metadata.php:63
__construct(private Filesystem $filesystem, protected string $dir)
RecursiveDirectoryIterator constructor.
The filesystem interface provides the public interface for the Filesystem service API consumer.
Definition: Filesystem.php:37
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.