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

Breadcrumb

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

function vfsStream::addStructure

helper method to create subdirectories recursively

Parameters

array $structure subdirectory structure to add:

vfsStreamDirectory $baseDir directory to add the structure to:

Return value

vfsStreamDirectory

1 call to vfsStream::addStructure()
vfsStream::create in vendor/mikey179/vfsstream/src/main/php/org/bovigo/vfs/vfsStream.php
creates vfsStream directory structure from an array and adds it to given base dir

File

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

Class

vfsStream
Some utility methods for vfsStream.

Namespace

org\bovigo\vfs

Code

protected static function addStructure(array $structure, vfsStreamDirectory $baseDir) {
    foreach ($structure as $name => $data) {
        $name = (string) $name;
        if (is_array($data) === true) {
            self::addStructure($data, self::newDirectory($name)->at($baseDir));
        }
        elseif (is_string($data) === true) {
            $matches = null;
            preg_match('/^\\[(.*)\\]$/', $name, $matches);
            if ($matches !== array()) {
                self::newBlock($matches[1])->withContent($data)
                    ->at($baseDir);
            }
            else {
                self::newFile($name)->withContent($data)
                    ->at($baseDir);
            }
        }
        elseif ($data instanceof FileContent) {
            self::newFile($name)->withContent($data)
                ->at($baseDir);
        }
        elseif ($data instanceof vfsStreamFile) {
            $baseDir->addChild($data);
        }
    }
    return $baseDir;
}

API Navigation

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