Set/get path for storages.

@param string $path Default null which means not set.
@param bool $force Default false.
@return string If null, then not set.
@throws \Exception
511141
public static function path(?string $path = null, bool $force = false): ?string
    {
        if ($path !== null || $force) {
            if ($path !== null) {
                if (!is_writable($path)) {
                    throw new \Exception('Path is not writable.');
                }
            }
            self::$path = $path !== null ? rtrim($path, '/') : $path;
        }
        return self::$path;
    }
906622
private function getValidPath($path)
    {
        // If `$path` is array
        if (is_array($path)) {
            return $this->getPathFromArray($path);
        }

        // If `$path` is a directory
        if (is_dir($path)) {
            $paths = glob($path . '/*.*');
            if (empty($paths)) {
                throw new EmptyDirectoryException("Configuration directory: [$path] is empty");
            }
            return $paths;
        }

        // If `$path` is not a file, throw an exception
        if (!file_exists($path)) {
            throw new FileNotFoundException("Configuration file: [$path] cannot be found");
        }
        return array($path);
    }
1026254
protected function getMediaRelativePath($path)
    {
        $path = self::validatePath($path, true);

        if (substr($path, 0, $this->storageFolderNameLength) == $this->storageFolder) {
            return substr($path, $this->storageFolderNameLength);
        }

        throw new SystemException(sprintf('Cannot convert Media Library path "%s" to a path relative to the Library root.', $path));
    }
797870
public static function createFromPath($path)
    {
        if (!file_exists($path)) {
            throw new Exception\FactoryException(sprintf('Unable to open file %s', $path));
        }
        $file = new \SplFileInfo($path);
        return static::createFromSplFileInfo($file);
    }
1196625
public function getLocatorPath($path)
	{
		if (!isset($this->locator->$path))
		{
			return false;
		}

		return $this->locator->$path;
	}
885388
public function setPath(string $path = null)
    {
        if ($path === null) {
            $uri = $this->server->get('REQUEST_URI');

            if (empty($uri)) {
                // Default to a slash
                $this->path = '/';
            } else {
                $uriParts = explode('?', $uri);
                $this->path = $uriParts[0];
            }
        } else {
            $this->path = $path;
        }
    }
151040
public function get($path, $default = null)
    {
        list($name, $path) = $this->splitPath($path);

        $config = $this->load($name);

        return empty($path) ? $config : $config->get($path, $default);
    }
359631
public function locate($path)
    {
        $repository = $this->getRepository();

        if(!$repository->contains($path)){
            throw new \InvalidArgumentException(sprintf('Their is no path %s in repository.', $path));
        }

        $resource = $repository->get($path);

        if(!($resource instanceof FilesystemResource)){
            throw new \RuntimeException(['Expect %s! %s given', FilesystemResource::class, get_class($resource)]);
        }

        return $resource;
    }
1106058
public function get($path, $default=Null)
    {
        $current = $this->data;
        $p = strtok($path, '.');

        while ($p !== false) {
            if (!isset($current[$p])) {
                return is_null($default) ? $this->getDefault($path) : $default;
            }
            $current = $current[$p];
            $p = strtok('.');
        }

        return $current;
    }
748794
protected function _prepareFilePath($path = null) {
		if (empty($path)) {
			return false;
		}

		if (DIRECTORY_SEPARATOR !== '\\') {
			return $path;
		}

		$path = str_replace('\\', '/', $path);

		return $path;
	}
930192
public static function getRealPath(string $path) : string
    {
        $exception = null;

        try {
            $result = ErrorCatcher::run(static function() use ($path) {
                return realpath($path);
            });

            if ($result !== false) {
                return $result;
            }
        } catch (\ErrorException $e) {
            $exception = $e;
        }

        throw new IoException('Error getting real path of ' . $path . ', check that the path exists', 0, $exception);
    }
321333
public static function rmdir( $dirPath, $force = false )
    {
        $_path = rtrim( $dirPath ) . DIRECTORY_SEPARATOR;

        if ( !$force )
        {
            return rmdir( $_path );
        }

        if ( !is_dir( $_path ) )
        {
            throw new \InvalidArgumentException( '"' . $_path . '" is not a directory or bogus in some other way.' );
        }

        $_files = glob( $_path . '*', GLOB_MARK );

        foreach ( $_files as $_file )
        {
            if ( is_dir( $_file ) )
            {
                static::rmdir( $_file, true );
            }
            else
            {
                unlink( $_file );
            }
        }

        return rmdir( $_path );
    }
66260
protected function remove($path, $force = false, $recursive = false) {
		$stat = $this->stat($path);
		$stat['realpath'] = $path;
		$this->rmTmb($stat);
		$this->clearcache();
	
		if (empty($stat)) {
			return $this->setError(elFinder::ERROR_RM, $this->_path($path), elFinder::ERROR_FILE_NOT_FOUND);
		}
	
		if (!$force && !empty($stat['locked'])) {
			return $this->setError(elFinder::ERROR_LOCKED, $this->_path($path));
		}
	
		if ($stat['mime'] == 'directory') {
			if (!$recursive && !$this->_rmdir($path)) {
				return $this->setError(elFinder::ERROR_RM, $this->_path($path));
			}
		} else {
			if (!$recursive && !$this->_unlink($path)) {
				return $this->setError(elFinder::ERROR_RM, $this->_path($path));
			}
		}
	
		$this->removed[] = $stat;
		return true;
	}
857711
public static function getPath($path = '')
    {
        $path = ltrim($path, '/\\');
        $path = sprintf('%s%s%s', self::$applicationRoot, DIRECTORY_SEPARATOR, $path);
        $path = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $path);
        return $path;
    }
1001141
public function setPath($path = null) : bool
    {
        if ($path === null) {
            $uri = $this->server->get('REQUEST_URI');

            if (!empty($uri)) {
                $uriParts = explode('?', $uri);
                $this->path = $uriParts[0];

                return true;
            }

            // Default to a slash
            $this->path = '/';

            return true;
        }

        $this->path = $path;

        return true;
    }
1170790
protected static function build_paths($force) {
        global $DB;

        if ($force or $DB->record_exists_select('context', "contextlevel = ".CONTEXT_COURSECAT." AND (depth = 0 OR path IS NULL)")) {
            if ($force) {
                $ctxemptyclause = $emptyclause = '';
            } else {
                $ctxemptyclause = "AND (ctx.path IS NULL OR ctx.depth = 0)";
                $emptyclause    = "AND ({context}.path IS NULL OR {context}.depth = 0)";
            }

            $base = '/'.SYSCONTEXTID;

            // Normal top level categories
            $sql = "UPDATE {context}
                       SET depth=2,
                           path=".$DB->sql_concat("'$base/'", 'id')."
                     WHERE contextlevel=".CONTEXT_COURSECAT."
                           AND EXISTS (SELECT 'x'
                                         FROM {course_categories} cc
                                        WHERE cc.id = {context}.instanceid AND cc.depth=1)
                           $emptyclause";
            $DB->execute($sql);

            // Deeper categories - one query per depthlevel
            $maxdepth = $DB->get_field_sql("SELECT MAX(depth) FROM {course_categories}");
            for ($n=2; $n<=$maxdepth; $n++) {
                $sql = "INSERT INTO {context_temp} (id, path, depth, locked)
                        SELECT ctx.id, ".$DB->sql_concat('pctx.path', "'/'", 'ctx.id').", pctx.depth+1, ctx.locked
                          FROM {context} ctx
                          JOIN {course_categories} cc ON (cc.id = ctx.instanceid AND ctx.contextlevel = ".CONTEXT_COURSECAT." AND cc.depth = $n)
                          JOIN {context} pctx ON (pctx.instanceid = cc.parent AND pctx.contextlevel = ".CONTEXT_COURSECAT.")
                         WHERE pctx.path IS NOT NULL AND pctx.depth > 0
                               $ctxemptyclause";
                $trans = $DB->start_delegated_transaction();
                $DB->delete_records('context_temp');
                $DB->execute($sql);
                context::merge_context_temp_table();
                $DB->delete_records('context_temp');
                $trans->allow_commit();

            }
        }
    }
109035
public function setPath(string $path)
    {
        $path = '/' . ltrim($path, '/');
        $this->query = null;
        $this->fragment = null;
        if (preg_match('/^(.*?)(\\?([^#]*))?(#(.*))?$/u', $path, $matches))
        {
            $path = $matches[1];
            $this->query = !empty($matches[3]) ? $matches[3] : null;
            $this->fragment = !empty($matches[5]) ? $matches[5] : null;
        }

        $this->path = $path;
        return $this;
    }