You are here

class vfsStreamStructureVisitor in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/mikey179/vfsStream/src/main/php/org/bovigo/vfs/visitor/vfsStreamStructureVisitor.php \org\bovigo\vfs\visitor\vfsStreamStructureVisitor

Visitor which traverses a content structure recursively to create an array structure from it.

@since 0.10.0

Hierarchy

Expanded class hierarchy of vfsStreamStructureVisitor

See also

https://github.com/mikey179/vfsStream/issues/10

1 file declares its use of vfsStreamStructureVisitor
KernelTestBaseTest.php in core/tests/Drupal/KernelTests/KernelTestBaseTest.php
Contains \Drupal\KernelTests\KernelTestBaseTest.

File

vendor/mikey179/vfsStream/src/main/php/org/bovigo/vfs/visitor/vfsStreamStructureVisitor.php, line 21

Namespace

org\bovigo\vfs\visitor
View source
class vfsStreamStructureVisitor extends vfsStreamAbstractVisitor {

  /**
   * collected structure
   *
   * @type  array
   */
  protected $structure = array();

  /**
   * poiting to currently iterated directory
   *
   * @type  array
   */
  protected $current;

  /**
   * constructor
   *
   * @api
   */
  public function __construct() {
    $this
      ->reset();
  }

  /**
   * visit a file and process it
   *
   * @param   vfsStreamFile  $file
   * @return  vfsStreamStructureVisitor
   */
  public function visitFile(vfsStreamFile $file) {
    $this->current[$file
      ->getName()] = $file
      ->getContent();
    return $this;
  }

  /**
   * visit a block device and process it
   *
   * @param   vfsStreamBlock $block
   * @return  vfsStreamStructureVisitor
   */
  public function visitBlockDevice(vfsStreamBlock $block) {
    $this->current['[' . $block
      ->getName() . ']'] = $block
      ->getContent();
    return $this;
  }

  /**
   * visit a directory and process it
   *
   * @param   vfsStreamDirectory  $dir
   * @return  vfsStreamStructureVisitor
   */
  public function visitDirectory(vfsStreamDirectory $dir) {
    $this->current[$dir
      ->getName()] = array();
    $tmp =& $this->current;
    $this->current =& $tmp[$dir
      ->getName()];
    foreach ($dir as $child) {
      $this
        ->visit($child);
    }
    $this->current =& $tmp;
    return $this;
  }

  /**
   * returns structure of visited contents
   *
   * @return  array
   * @api
   */
  public function getStructure() {
    return $this->structure;
  }

  /**
   * resets structure so visitor could be reused
   *
   * @return  vfsStreamStructureVisitor
   */
  public function reset() {
    $this->structure = array();
    $this->current =& $this->structure;
    return $this;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
vfsStreamAbstractVisitor::visit public function visit a content and process it Overrides vfsStreamVisitor::visit
vfsStreamStructureVisitor::$current protected property poiting to currently iterated directory
vfsStreamStructureVisitor::$structure protected property collected structure
vfsStreamStructureVisitor::getStructure public function returns structure of visited contents
vfsStreamStructureVisitor::reset public function resets structure so visitor could be reused
vfsStreamStructureVisitor::visitBlockDevice public function visit a block device and process it Overrides vfsStreamAbstractVisitor::visitBlockDevice
vfsStreamStructureVisitor::visitDirectory public function visit a directory and process it Overrides vfsStreamVisitor::visitDirectory
vfsStreamStructureVisitor::visitFile public function visit a file and process it Overrides vfsStreamVisitor::visitFile
vfsStreamStructureVisitor::__construct public function constructor