org\bovigo\vfs\vfsStream::newDirectory PHP Method

newDirectory() public static method

If the name contains slashes, a new directory structure will be created. The returned directory will always be the parent directory of this directory structure.
public static newDirectory ( string $name, integer $permissions = null ) : vfsStreamDirectory
$name string name of directory to create
$permissions integer permissions of directory to create
return vfsStreamDirectory
    public static function newDirectory($name, $permissions = null)
    {
        if ('/' === $name[0]) {
            $name = substr($name, 1);
        }
        $firstSlash = strpos($name, '/');
        if (false === $firstSlash) {
            return new vfsStreamDirectory($name, $permissions);
        }
        $ownName = substr($name, 0, $firstSlash);
        $subDirs = substr($name, $firstSlash + 1);
        $directory = new vfsStreamDirectory($ownName, $permissions);
        if (is_string($subDirs) && strlen($subDirs) > 0) {
            self::newDirectory($subDirs, $permissions)->at($directory);
        }
        return $directory;
    }

Usage Example

 /**
  * @test
  */
 public function visitDirectoryWritesDirectoryNameToStream()
 {
     $output = vfsStream::newFile('foo.txt')->at(vfsStream::setup());
     $printVisitor = new vfsStreamPrintVisitor(fopen('vfs://root/foo.txt', 'wb'));
     $this->assertSame($printVisitor, $printVisitor->visitDirectory(vfsStream::newDirectory('baz')));
     $this->assertEquals("- baz\n", $output->getContent());
 }
All Usage Examples Of org\bovigo\vfs\vfsStream::newDirectory