Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. vfsStream.php

function vfsStream::create

creates vfsStream directory structure from an array and adds it to given base dir

Assumed $structure contains an array like this: <code> array('Core' = array('AbstractFactory' => array('test.php' => 'some text content', 'other.php' => 'Some more text content', 'Invalid.csv' => 'Something else', ), 'AnEmptyFolder' => array(), 'badlocation.php' => 'some bad content', ) ) </code> the resulting directory tree will look like this: <pre> baseDir \- Core |- badlocation.php |- AbstractFactory | |- test.php | |- other.php | \- Invalid.csv \- AnEmptyFolder </pre> Arrays will become directories with their key as directory name, and strings becomes files with their key as file name and their value as file content.

If no baseDir is given it will try to add the structure to the existing root directory without replacing existing childs except those with equal names.

@since 0.10.0

Parameters

array $structure directory structure to add under root directory:

vfsStreamDirectory $baseDir base directory to add structure to:

Return value

vfsStreamDirectory

Throws

\InvalidArgumentException

See also

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

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

1 call to vfsStream::create()
vfsStream::setup in vendor/mikey179/vfsstream/src/main/php/org/bovigo/vfs/vfsStream.php
helper method for setting up vfsStream in unit tests

File

vendor/mikey179/vfsstream/src/main/php/org/bovigo/vfs/vfsStream.php, line 211

Class

vfsStream
Some utility methods for vfsStream.

Namespace

org\bovigo\vfs

Code

public static function create(array $structure, ?vfsStreamDirectory $baseDir = null) {
    if (null === $baseDir) {
        $baseDir = vfsStreamWrapper::getRoot();
    }
    if (null === $baseDir) {
        throw new \InvalidArgumentException('No baseDir given and no root directory set.');
    }
    return self::addStructure($structure, $baseDir);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal