You are here

class vfsStreamDirectory in Zircon Profile 8

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

Directory container.

@api

Hierarchy

Expanded class hierarchy of vfsStreamDirectory

7 files declare their use of vfsStreamDirectory
PermissionHandlerTest.php in core/modules/user/tests/src/Unit/PermissionHandlerTest.php
Contains \Drupal\Tests\user\Unit\PermissionHandlerTest.
vfsStreamAbstractVisitorTestCase.php in vendor/mikey179/vfsStream/src/test/php/org/bovigo/vfs/visitor/vfsStreamAbstractVisitorTestCase.php
vfsStreamPrintVisitor.php in vendor/mikey179/vfsStream/src/main/php/org/bovigo/vfs/visitor/vfsStreamPrintVisitor.php
vfsStreamPrintVisitorTestCase.php in vendor/mikey179/vfsStream/src/test/php/org/bovigo/vfs/visitor/vfsStreamPrintVisitorTestCase.php
vfsStreamStructureVisitor.php in vendor/mikey179/vfsStream/src/main/php/org/bovigo/vfs/visitor/vfsStreamStructureVisitor.php

... See full list

File

vendor/mikey179/vfsStream/src/main/php/org/bovigo/vfs/vfsStreamDirectory.php, line 16

Namespace

org\bovigo\vfs
View source
class vfsStreamDirectory extends vfsStreamAbstractContent implements vfsStreamContainer {

  /**
   * list of directory children
   *
   * @type  vfsStreamContent[]
   */
  protected $children = array();

  /**
   * constructor
   *
   * @param   string  $name
   * @param   int     $permissions  optional
   * @throws  vfsStreamException
   */
  public function __construct($name, $permissions = null) {
    if (strstr($name, '/') !== false) {
      throw new vfsStreamException('Directory name can not contain /.');
    }
    $this->type = vfsStreamContent::TYPE_DIR;
    parent::__construct($name, $permissions);
  }

  /**
   * returns default permissions for concrete implementation
   *
   * @return  int
   * @since   0.8.0
   */
  protected function getDefaultPermissions() {
    return 0777;
  }

  /**
   * returns size of directory
   *
   * The size of a directory is always 0 bytes. To calculate the summarized
   * size of all children in the directory use sizeSummarized().
   *
   * @return  int
   */
  public function size() {
    return 0;
  }

  /**
   * returns summarized size of directory and its children
   *
   * @return  int
   */
  public function sizeSummarized() {
    $size = 0;
    foreach ($this->children as $child) {
      if ($child
        ->getType() === vfsStreamContent::TYPE_DIR) {
        $size += $child
          ->sizeSummarized();
      }
      else {
        $size += $child
          ->size();
      }
    }
    return $size;
  }

  /**
   * renames the content
   *
   * @param   string  $newName
   * @throws  vfsStreamException
   */
  public function rename($newName) {
    if (strstr($newName, '/') !== false) {
      throw new vfsStreamException('Directory name can not contain /.');
    }
    parent::rename($newName);
  }

  /**
   * sets parent path
   *
   * @param  string  $parentPath
   * @internal  only to be set by parent
   * @since   1.2.0
   */
  public function setParentPath($parentPath) {
    parent::setParentPath($parentPath);
    foreach ($this->children as $child) {
      $child
        ->setParentPath($this
        ->path());
    }
  }

  /**
   * adds child to the directory
   *
   * @param  vfsStreamContent  $child
   */
  public function addChild(vfsStreamContent $child) {
    $child
      ->setParentPath($this
      ->path());
    $this->children[$child
      ->getName()] = $child;
    $this
      ->updateModifications();
  }

  /**
   * removes child from the directory
   *
   * @param   string  $name
   * @return  bool
   */
  public function removeChild($name) {
    foreach ($this->children as $key => $child) {
      if ($child
        ->appliesTo($name)) {
        $child
          ->setParentPath(null);
        unset($this->children[$key]);
        $this
          ->updateModifications();
        return true;
      }
    }
    return false;
  }

  /**
   * updates internal timestamps
   */
  protected function updateModifications() {
    $time = time();
    $this->lastAttributeModified = $time;
    $this->lastModified = $time;
  }

  /**
   * checks whether the container contains a child with the given name
   *
   * @param   string  $name
   * @return  bool
   */
  public function hasChild($name) {
    return $this
      ->getChild($name) !== null;
  }

  /**
   * returns the child with the given name
   *
   * @param   string  $name
   * @return  vfsStreamContent
   */
  public function getChild($name) {
    $childName = $this
      ->getRealChildName($name);
    foreach ($this->children as $child) {
      if ($child
        ->getName() === $childName) {
        return $child;
      }
      if ($child
        ->appliesTo($childName) === true && $child
        ->hasChild($childName) === true) {
        return $child
          ->getChild($childName);
      }
    }
    return null;
  }

  /**
   * helper method to detect the real child name
   *
   * @param   string  $name
   * @return  string
   */
  protected function getRealChildName($name) {
    if ($this
      ->appliesTo($name) === true) {
      return self::getChildName($name, $this->name);
    }
    return $name;
  }

  /**
   * helper method to calculate the child name
   *
   * @param   string  $name
   * @param   string  $ownName
   * @return  string
   */
  protected static function getChildName($name, $ownName) {
    if ($name === $ownName) {
      return $name;
    }
    return substr($name, strlen($ownName) + 1);
  }

  /**
   * checks whether directory contains any children
   *
   * @return  bool
   * @since   0.10.0
   */
  public function hasChildren() {
    return count($this->children) > 0;
  }

  /**
   * returns a list of children for this directory
   *
   * @return  vfsStreamContent[]
   */
  public function getChildren() {
    return array_values($this->children);
  }

  /**
   * returns iterator for the children
   *
   * @return  vfsStreamContainerIterator
   */
  public function getIterator() {
    return new vfsStreamContainerIterator($this->children);
  }

  /**
   * checks whether dir is a dot dir
   *
   * @return  bool
   */
  public function isDot() {
    if ('.' === $this->name || '..' === $this->name) {
      return true;
    }
    return false;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
vfsStreamAbstractContent::$group protected property owner group of the file
vfsStreamAbstractContent::$lastAccessed protected property timestamp of last access
vfsStreamAbstractContent::$lastAttributeModified protected property timestamp of last attribute modification
vfsStreamAbstractContent::$lastModified protected property timestamp of last modification
vfsStreamAbstractContent::$name protected property name of the container
vfsStreamAbstractContent::$parentPath private property path to to this content
vfsStreamAbstractContent::$permissions protected property permissions for content
vfsStreamAbstractContent::$type protected property type of the container
vfsStreamAbstractContent::$user protected property owner of the file
vfsStreamAbstractContent::appliesTo public function checks whether the container can be applied to given name Overrides vfsStreamContent::appliesTo 1
vfsStreamAbstractContent::at public function adds content to given container Overrides vfsStreamContent::at
vfsStreamAbstractContent::chgrp public function change owner group of file to given group Overrides vfsStreamContent::chgrp
vfsStreamAbstractContent::chmod public function change file mode to given permissions Overrides vfsStreamContent::chmod
vfsStreamAbstractContent::chown public function change owner of file to given user Overrides vfsStreamContent::chown
vfsStreamAbstractContent::fileatime public function returns the last access time of the stream content
vfsStreamAbstractContent::filectime public function returns the last attribute modification time of the stream content
vfsStreamAbstractContent::filemtime public function returns the last modification time of the stream content Overrides vfsStreamContent::filemtime
vfsStreamAbstractContent::getGroup public function returns owner group of file Overrides vfsStreamContent::getGroup
vfsStreamAbstractContent::getName public function returns the file name of the content Overrides vfsStreamContent::getName
vfsStreamAbstractContent::getPermissions public function returns permissions Overrides vfsStreamContent::getPermissions
vfsStreamAbstractContent::getType public function returns the type of the container Overrides vfsStreamContent::getType
vfsStreamAbstractContent::getUser public function returns owner of file Overrides vfsStreamContent::getUser
vfsStreamAbstractContent::isExecutable public function checks whether content is executable Overrides vfsStreamContent::isExecutable
vfsStreamAbstractContent::isOwnedByGroup public function checks whether file is owned by group Overrides vfsStreamContent::isOwnedByGroup
vfsStreamAbstractContent::isOwnedByUser public function checks whether file is owned by given user Overrides vfsStreamContent::isOwnedByUser
vfsStreamAbstractContent::isReadable public function checks whether content is readable Overrides vfsStreamContent::isReadable
vfsStreamAbstractContent::isWritable public function checks whether content is writable Overrides vfsStreamContent::isWritable
vfsStreamAbstractContent::lastAccessed public function sets last access time of the stream content
vfsStreamAbstractContent::lastAttributeModified public function sets the last attribute modification time of the stream content
vfsStreamAbstractContent::lastModified public function sets the last modification time of the stream content Overrides vfsStreamContent::lastModified
vfsStreamAbstractContent::path public function returns path to this content Overrides vfsStreamContent::path
vfsStreamAbstractContent::url public function returns complete vfsStream url for this content Overrides vfsStreamContent::url
vfsStreamContent::TYPE_BLOCK constant stream content type: block
vfsStreamContent::TYPE_DIR constant stream content type: directory
vfsStreamContent::TYPE_FILE constant stream content type: file
vfsStreamDirectory::$children protected property list of directory children
vfsStreamDirectory::addChild public function adds child to the directory Overrides vfsStreamContainer::addChild
vfsStreamDirectory::getChild public function returns the child with the given name Overrides vfsStreamContainer::getChild
vfsStreamDirectory::getChildName protected static function helper method to calculate the child name
vfsStreamDirectory::getChildren public function returns a list of children for this directory Overrides vfsStreamContainer::getChildren
vfsStreamDirectory::getDefaultPermissions protected function returns default permissions for concrete implementation Overrides vfsStreamAbstractContent::getDefaultPermissions
vfsStreamDirectory::getIterator public function returns iterator for the children 1
vfsStreamDirectory::getRealChildName protected function helper method to detect the real child name
vfsStreamDirectory::hasChild public function checks whether the container contains a child with the given name Overrides vfsStreamContainer::hasChild
vfsStreamDirectory::hasChildren public function checks whether directory contains any children Overrides vfsStreamContainer::hasChildren
vfsStreamDirectory::isDot public function checks whether dir is a dot dir 1
vfsStreamDirectory::removeChild public function removes child from the directory Overrides vfsStreamContainer::removeChild
vfsStreamDirectory::rename public function renames the content Overrides vfsStreamAbstractContent::rename
vfsStreamDirectory::setParentPath public function sets parent path Overrides vfsStreamAbstractContent::setParentPath
vfsStreamDirectory::size public function returns size of directory Overrides vfsStreamContent::size
vfsStreamDirectory::sizeSummarized public function returns summarized size of directory and its children
vfsStreamDirectory::updateModifications protected function updates internal timestamps
vfsStreamDirectory::__construct public function constructor Overrides vfsStreamAbstractContent::__construct