You are here

public static function vfsStream::copyFromFileSystem in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/mikey179/vfsStream/src/main/php/org/bovigo/vfs/vfsStream.php \org\bovigo\vfs\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

7 calls to vfsStream::copyFromFileSystem()
vfsStreamTestCase::copyFromEmptyFolder in vendor/mikey179/vfsStream/src/test/php/org/bovigo/vfs/vfsStreamTestCase.php
@test @group issue_4 @since 0.11.0
vfsStreamTestCase::copyFromEmptyFolderWithRoot in vendor/mikey179/vfsStream/src/test/php/org/bovigo/vfs/vfsStreamTestCase.php
@test @group issue_4 @since 0.11.0
vfsStreamTestCase::copyFromFileSystemMocksLargeFiles in vendor/mikey179/vfsStream/src/test/php/org/bovigo/vfs/vfsStreamTestCase.php
To test this the max file size is reduced to something reproduceable.
vfsStreamTestCase::copyFromFileSystemThrowsExceptionIfNoBaseDirGivenAndNoRootSet in vendor/mikey179/vfsStream/src/test/php/org/bovigo/vfs/vfsStreamTestCase.php
@test @group issue_4 @expectedException \InvalidArgumentException @since 0.11.0
vfsStreamTestCase::copyFromPreservesFilePermissions in vendor/mikey179/vfsStream/src/test/php/org/bovigo/vfs/vfsStreamTestCase.php
@test @group issue_4 @group issue_29 @since 0.11.2

... See full list

File

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

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;
}