name = $name; } /** * @return string */ public function getName(): string { return $this->name; } /** * @return int */ public function getSize(): int { $size = 0; foreach ($this->children as $child) { $size += $child->getSize(); } return $size; } /** * @param string $prefix * @return void */ public function display(string $prefix = ''): void { echo $prefix . ":directory:" . $this->name . '(' . $this->getSize() . 'bytes)' . PHP_EOL; foreach ($this->children as $child) { $child->display($prefix ,' '); } } /** * @param FileSystemComponentInterface $component * @return void */ public function add(FileSystemComponentInterface $component): void { $this->children[] = $component; } /** * @param FileSystemComponentInterface $component * @return void */ public function remove(FileSystemComponentInterface $component): void { $this->children = array_filter($this->children, function ($c) use ($component) { return $c !== $component; }); } }