class vfsStreamPrintVisitor in Zircon Profile 8.0
Same name and namespace in other branches
- 8 vendor/mikey179/vfsStream/src/main/php/org/bovigo/vfs/visitor/vfsStreamPrintVisitor.php \org\bovigo\vfs\visitor\vfsStreamPrintVisitor
Visitor which traverses a content structure recursively to print it to an output stream.
@since 0.10.0
Hierarchy
- class \org\bovigo\vfs\visitor\vfsStreamAbstractVisitor implements vfsStreamVisitor
- class \org\bovigo\vfs\visitor\vfsStreamPrintVisitor
Expanded class hierarchy of vfsStreamPrintVisitor
See also
https://github.com/mikey179/vfsStream/issues/10
1 file declares its use of vfsStreamPrintVisitor
- KernelTestBase.php in core/
tests/ Drupal/ KernelTests/ KernelTestBase.php - Contains \Drupal\KernelTests\KernelTestBase.
File
- vendor/
mikey179/ vfsStream/ src/ main/ php/ org/ bovigo/ vfs/ visitor/ vfsStreamPrintVisitor.php, line 22
Namespace
org\bovigo\vfs\visitorView source
class vfsStreamPrintVisitor extends vfsStreamAbstractVisitor {
/**
* target to write output to
*
* @type resource
*/
protected $out;
/**
* current depth in directory tree
*
* @type int
*/
protected $depth;
/**
* constructor
*
* If no file pointer given it will fall back to STDOUT.
*
* @param resource $out optional
* @throws \InvalidArgumentException
* @api
*/
public function __construct($out = STDOUT) {
if (is_resource($out) === false || get_resource_type($out) !== 'stream') {
throw new \InvalidArgumentException('Given filepointer is not a resource of type stream');
}
$this->out = $out;
}
/**
* visit a file and process it
*
* @param vfsStreamFile $file
* @return vfsStreamPrintVisitor
*/
public function visitFile(vfsStreamFile $file) {
$this
->printContent($file
->getName());
return $this;
}
/**
* visit a block device and process it
*
* @param vfsStreamBlock $block
* @return vfsStreamPrintVisitor
*/
public function visitBlockDevice(vfsStreamBlock $block) {
$name = '[' . $block
->getName() . ']';
$this
->printContent($name);
return $this;
}
/**
* visit a directory and process it
*
* @param vfsStreamDirectory $dir
* @return vfsStreamPrintVisitor
*/
public function visitDirectory(vfsStreamDirectory $dir) {
$this
->printContent($dir
->getName());
$this->depth++;
foreach ($dir as $child) {
$this
->visit($child);
}
$this->depth--;
return $this;
}
/**
* helper method to print the content
*
* @param string $name
*/
protected function printContent($name) {
fwrite($this->out, str_repeat(' ', $this->depth) . '- ' . $name . "\n");
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
vfsStreamAbstractVisitor:: |
public | function |
visit a content and process it Overrides vfsStreamVisitor:: |
|
vfsStreamPrintVisitor:: |
protected | property | current depth in directory tree | |
vfsStreamPrintVisitor:: |
protected | property | target to write output to | |
vfsStreamPrintVisitor:: |
protected | function | helper method to print the content | |
vfsStreamPrintVisitor:: |
public | function |
visit a block device and process it Overrides vfsStreamAbstractVisitor:: |
|
vfsStreamPrintVisitor:: |
public | function |
visit a directory and process it Overrides vfsStreamVisitor:: |
|
vfsStreamPrintVisitor:: |
public | function |
visit a file and process it Overrides vfsStreamVisitor:: |
|
vfsStreamPrintVisitor:: |
public | function | constructor |