org\bovigo\vfs\vfsStream::copyFromFileSystem PHP Метод

copyFromFileSystem() публичный статический Метод

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.
См. также: https://github.com/mikey179/vfsStream/issues/4
С версии: 0.11.0
public static copyFromFileSystem ( string $path, vfsStreamDirectory $baseDir = null, integer $maxFileSize = 1048576 ) : vfsStreamDirectory
$path string path to copy the structure from
$baseDir vfsStreamDirectory directory to add the structure to
$maxFileSize integer maximum file size of files to copy content from
Результат vfsStreamDirectory
    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;
    }

Usage Example

Пример #1
0
 /**
  * Set up for each test
  */
 public function setUp()
 {
     // setup
     $this->root = vfsStream::setup('assets');
     // Copy directory structure from file system
     vfsStream::copyFromFileSystem(__DIR__ . '/assets');
 }
All Usage Examples Of org\bovigo\vfs\vfsStream::copyFromFileSystem