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

Breadcrumb

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

function vfsStream::copyFromFileSystem

copies the file system structure from given path into the base dir

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. File permissions are copied as well. Please note that file contents will only be copied if their file size does not exceed the given $maxFileSize which defaults to 1024 KB. In case the file is larger file content will be mocked, see https://github.com/mikey179/vfsStream/wiki/MockingLargeFiles.

@since 0.11.0

Parameters

string $path path to copy the structure from:

vfsStreamDirectory $baseDir directory to add the structure to:

int $maxFileSize maximum file size of files to copy content from:

Return value

vfsStreamDirectory

Throws

\InvalidArgumentException

See also

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

File

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

Class

vfsStream
Some utility methods for vfsStream.

Namespace

org\bovigo\vfs

Code

public static function copyFromFileSystem($path, ?vfsStreamDirectory $baseDir = null, $maxFileSize = 1048576) {
    if (null === $baseDir) {
        $baseDir = vfsStreamWrapper::getRoot();
    }
    if (null === $baseDir) {
        throw new \InvalidArgumentException('No baseDir given and no root directory set.');
    }
    $dir = new \DirectoryIterator($path);
    foreach ($dir as $fileinfo) {
        switch (filetype($fileinfo->getPathname())) {
            case 'file':
                if ($fileinfo->getSize() <= $maxFileSize) {
                    $content = file_get_contents($fileinfo->getPathname());
                }
                else {
                    $content = new LargeFileContent($fileinfo->getSize());
                }
                self::newFile($fileinfo->getFilename(), octdec(substr(sprintf('%o', $fileinfo->getPerms()), -4)))
                    ->withContent($content)
                    ->at($baseDir);
                break;
            case 'dir':
                if (!$fileinfo->isDot()) {
                    self::copyFromFileSystem($fileinfo->getPathname(), self::newDirectory($fileinfo->getFilename(), octdec(substr(sprintf('%o', $fileinfo->getPerms()), -4)))
                        ->at($baseDir), $maxFileSize);
                }
                break;
            case 'block':
                self::newBlock($fileinfo->getFilename(), octdec(substr(sprintf('%o', $fileinfo->getPerms()), -4)))
                    ->at($baseDir);
                break;
        }
    }
    return $baseDir;
}

API Navigation

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