Kahlan\Dir\Dir::make PHP Method

make() public static method

Creates a directory.
public static make ( array | string $path, array $options = [] ) : boolean
$path array | string The directory path.
$options array Possible options values are: -`'mode'` _integer_ : Mode used for directory creation. -`'recursive'` _boolean_ : Scans recursively if `true`.
return boolean
    public static function make($path, $options = [])
    {
        $defaults = ['mode' => 0755, 'recursive' => true];
        $options += $defaults;
        if (!is_array($path)) {
            return mkdir($path, $options['mode'], $options['recursive']);
        }
        $result = [];
        foreach ($path as $p) {
            $result[] = static::make($p, $options);
        }
        return !!array_filter($result);
    }

Usage Example

Beispiel #1
0
            $stat = stat($path);
            $mode = $stat['mode'] & 0777;
            expect($mode)->toBe(0755);
        });
        it("creates a nested directory with a specific mode", function () {
            $path = $this->tmpDir . '/My/Nested/Directory';
            $actual = Dir::make($path, ['mode' => 0777]);
            expect($actual)->toBe(true);
            expect(file_exists($path))->toBe(true);
            $stat = stat($path);
            $mode = $stat['mode'] & 0777;
            expect($mode)->toBe(0777);
        });
        it("creates multiple nested directories in a single call", function () {
            $paths = [$this->tmpDir . '/My/Nested/Directory', $this->tmpDir . '/Sub/Nested/Directory'];
            $actual = Dir::make($paths);
            expect($actual)->toBe(true);
            foreach ($paths as $path) {
                expect(file_exists($path))->toBe(true);
            }
        });
    });
    describe("::tempnam()", function () {
        it("uses the system temp directory by default", function () {
            $dir = Dir::tempnam(null, 'spec');
            $temp = sys_get_temp_dir();
            expect($this->normalize($dir))->toMatch('~' . $this->normalize($temp) . '/spe~');
            Dir::remove($dir);
        });
    });
});