/** * visit a content and process it * * @param vfsStreamContent $content * @return vfsStreamVisitor * @throws InvalidArgumentException */ public function visit(vfsStreamContent $content) { switch ($content->getType()) { case vfsStreamContent::TYPE_FILE: $this->visitFile($content); break; case vfsStreamContent::TYPE_DIR: $this->visitDirectory($content); break; default: throw new InvalidArgumentException('Unknown content type'); } return $this; }
/** * removes a directory * * @param string $path * @param int $options * @return bool * @todo consider $options with STREAM_MKDIR_RECURSIVE */ public function rmdir($path, $options) { $path = $this->resolvePath(vfsStream::path($path)); $child = $this->getContentOfType($path, vfsStreamContent::TYPE_DIR); if (null === $child) { return false; } // can only remove empty directories if (count($child->getChildren()) > 0) { return false; } if (self::$root->getName() === $path) { // delete root? very brave. :) self::$root = null; clearstatcache(); return true; } $names = $this->splitPath($path); $dir = $this->getContentOfType($names['dirname'], vfsStreamContent::TYPE_DIR); if ($dir->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup()) === false) { return false; } clearstatcache(); return $dir->removeChild($child->getName()); }
/** * helper method to print the content * * @param vfsStreamContent $content */ protected function printContent(vfsStreamContent $content) { fwrite($this->out, str_repeat(' ', $this->depth) . '- ' . $content->getName() . "\n"); }
/** * adds child to the directory * * @param vfsStreamContent $child */ public function addChild(vfsStreamContent $child) { $this->children[$child->getName()] = $child; $this->updateModifications(); }
/** * helper assertion for the tests * * @param string $url url to check * @param vfsStreamContent $content content to compare */ protected function assertFileTimesEqualStreamTimes($url, vfsStreamContent $content) { $this->assertEquals(filemtime($url), $content->filemtime()); $this->assertEquals(fileatime($url), $content->fileatime()); $this->assertEquals(filectime($url), $content->filectime()); }