src/fs/Temp.php
public static function createDir(
        string $prefix = "tmp",
        int $mode = 0777,
        int $maxAttempts = 10
    ): entity\DirEntity
    {
        $tmpdir = static::getDir();
        $prefix = \sndsgd\Fs::sanitizeName($prefix);
        $attempts = 0;
        do {
            $attempts++;
            if ($attempts > $maxAttempts) {
                throw new \RuntimeException(
                    "failed to create temp directory; ".
                    "reached max number ($maxAttempts) of attempts"
                );
            }
            $rand = \sndsgd\Str::random(10);
            $path = "$tmpdir/$prefix-$rand";
        }
        while (@mkdir($path, $mode) === false);

        $dir = new entity\DirEntity($path);
        static::registerEntity($dir);
        return $dir;
    }
public static function createDir(
        string $prefix = "tmp",
        int $mode = 0777,
        int $maxAttempts = 10
    ): entity\DirEntity
    {
        $tmpdir = static::getDir();
        $prefix = \sndsgd\Fs::sanitizeName($prefix);
        $attempts = 0;
        do {
            $attempts++;
            if ($attempts > $maxAttempts) {
                throw new \RuntimeException(
                    "failed to create temp directory; ".
                    "reached max number ($maxAttempts) of attempts"
                );
            }
            $rand = \sndsgd\Str::random(10);
            $path = "$tmpdir/$prefix-$rand";
        }
        while (@mkdir($path, $mode) === false);

        $dir = new entity\DirEntity($path);
        static::registerEntity($dir);
        return $dir;
    }
Create a temp directory

@param string $prefix A directory name prefix
@param int $mode The permissions for the new directory
@param int $maxAttempts The max number of times to call mkdir
@return \sndsgd\fs\entity\DirEntity