/** * * @param string $category * @param string $directoryName * @param bool $create * @param bool $required * @throws VarStoreException * @return \n2n\io\fs\FsPath */ public function requestDirFsPath($category, $module, $directoryName, $create = true, $required = true) { if (!in_array($category, self::getCategories())) { throw new \InvalidArgumentException('Invalid var category \'' . $category . '\'. Available categories: ' . implode(', ', self::getCategories())); } $dirPath = $this->varPath . DIRECTORY_SEPARATOR . $category; if (isset($module)) { $modulePathPart = self::namespaceToDirName((string) $module); $this->validatePathPart($modulePathPart); $dirPath .= DIRECTORY_SEPARATOR . $modulePathPart; } if (isset($directoryName)) { $this->validatePathPart($directoryName); $dirPath .= DIRECTORY_SEPARATOR . $directoryName; } $path = new FsPath($dirPath); if ($path->isDir()) { return $path; } if ($create) { if ($this->dirPerm === null) { throw new IllegalStateException('Dir perm not defined for VarStore. Could not create directory: ' . $path); } $path->mkdirs($this->dirPerm); return $path; } if (!$required) { return $path; } throw new InvalidPathException('Var directory not found: ' . $path); }