Get real path

@param string $path
@return string
192660
protected function realPath( $path )
    {
        $path = trim( str_replace( '\\', '/', $path ), '/' );
        $path = str_replace( '/./', '/', $path );
        $path = preg_replace( '#[^/]+/\\.\\./#', '/', $path );
        $path = preg_replace( '#/?\\.\\.?/#', '', $path );
        $path = preg_replace( '#/+#', '/', $path );
        $path = trim( $path, '/' );

        if ( $path == '.' || $path == '..' )
        {
            $path = '';
        }

        return $path;
    }
1164392
protected static function _realpath($path)
    {
        $realPath = realpath($path);
        if ($realPath !== false) {
            $path = $realPath;
        }

        return rtrim($path, '/\\');
    }
904030
protected function realpath(string $path): string
    {
        if ($path === '') {
            return $this->baseDir;
        }

        if ($path[0] === '/' || (!empty($path[1]) && $path[1] === ':')) {
            return $path;
        }

        return $this->baseDir . '/' . $path;
    }
520686
protected function get_pathfor($path = '') {
        $path = trim($path, '/') !== '' ? '/' . trim($path, '/') : '';
        return $this->connectionpoint->get_path() . '/' .
               'plugin_' . $this->plugintype . '_' .
               $this->pluginname . '_' . basename($this->connectionpoint->get_path()) . $path;
    }
489750
public function getRealPath()
    {
        $path = parent::getRealPath();
        if (empty($path)) {
            $path = $this->getRootDir().$this->getFilename();
        }
        return $path;
    }
1191781
public static function getNameFromPath($path)
    {
        $path = rtrim($path, '/'); // may be a folder
        if (empty($path)) {
            return '.';
        } // self directory

        $marker = strrpos($path, '/');
        if (false === $marker) {
            return $path;
        }

        return substr($path, $marker + 1);
    }
1300808
public function get_path($path)
	{
		$pathinfo = is_dir($path) ? array('dirname' => $path, 'extension' => null, 'basename' => '') : pathinfo($path);

		// make sure we have a dirname to work with
		isset($pathinfo['dirname']) or $pathinfo['dirname'] = '';

		// do we have a basedir, and is the path already prefixed by the basedir? then just deal with the double dots...
		if ( ! empty($this->basedir) && substr($pathinfo['dirname'], 0, strlen($this->basedir)) == $this->basedir)
		{
			$pathinfo['dirname'] = realpath($pathinfo['dirname']);
		}
		else
		{
			// attempt to get the realpath(), otherwise just use path with any double dots taken out when basedir is set (for security)
			$pathinfo['dirname'] = ( ! empty($this->basedir) ? realpath($this->basedir.DS.$pathinfo['dirname']) : realpath($pathinfo['dirname']) )
					?: ( ! empty($this->basedir) ? $this->basedir.DS.str_replace('..', '', $pathinfo['dirname']) : $pathinfo['dirname']);
		}

		// basedir prefix is required when it is set (may cause unexpected errors when realpath doesn't work)
		if ( ! empty($this->basedir) && substr($pathinfo['dirname'], 0, strlen($this->basedir)) != $this->basedir)
		{
			throw new \OutsideAreaException('File operation not allowed: given path is outside the basedir for this area.');
		}

		// check file extension
		if ( ! empty(static::$extensions) && array_key_exists($pathinfo['extension'], static::$extensions))
		{
			throw new \FileAccessException('File operation not allowed: disallowed file extension.');
		}

		return $pathinfo['dirname'].DS.$pathinfo['basename'];
	}
389216
protected function cleanPathInternal($path)
    {
        if ($this->isVirtual($path)) {
            return $this->cleanPath($path);
        }

        if ($this->hasCDBack($path)) {
            $realpath = $this->cleanPath(realpath($path));
            return $realpath ?: null;
        }

        return $this->cleanPath($path);
    }
1018486
public function normalizeDirectoryPath($path)
    {
        $path = $this->normalizePath($path);

        if (is_link($path)) {
            $path = realpath($path);
        }

        return $path;
    }
1207039
public function getRealPath($path, $rootDir)
    {
        if (!is_string($path)) {
            return false;
        }

        if ($this->isRelativePath($path)) {
            return realpath($rootDir . DIRECTORY_SEPARATOR . $path);
        }

        return realpath($path);
    }
641409
protected function realPath($path)
    {
        if (php_sapi_name() == 'cli' && ! $path) {
            $path = $_SERVER['DOCUMENT_ROOT'];
        }

        if ($realPath = realpath($path)) {
            $path = $realPath;
        }

        return rtrim($path, '/\\');
    }
335919
protected function getPath($path)
    {
        $hasHttp = strpos($path, 'http');
        if (false === $hasHttp || $hasHttp !== 0) {
            return $this->options['base_url'] . $path;
        }

        return $path;
    }
927834
protected function _path($path) {
		return $this->rootName.($path == $this->root ? '' : $this->separator.$this->_relpath($path));
	}
317963
public static function getFolder(string $path)
    {
        $arrFolders = explode(DIRECTORY_SEPARATOR, $path);
        $fullPath = "";
        if ($arrFolders[0] !== "") {
            $fullPath = $arrFolders[0];
        }
        unset($arrFolders[0]);
        foreach ($arrFolders as $folder) {
            $fullPath .= DIRECTORY_SEPARATOR . $folder;
            if (file_exists($fullPath) && is_dir($fullPath)) {
                continue;
            }
            mkdir($fullPath, 0775);
        }
        return $path;
    }
408241
public static function getUtilUrl($path)
    {
        global $CFG;
        if ( isset($CFG->utilroot) ) {
            return $CFG->utilroot.$path;
        }

        // From wwwroot
        $path = str_replace('.php','',$path);
        $retval = $CFG->wwwroot . '/util' . $path;
        return $retval;

        // The old way from "vendor"
        // return $CFG->vendorroot.$path;
    }
983339
public static function realPharPath($path)
    {
        if (strpos($path, 'phar:///') !== 0) {
            return;
        }
        
        $parts = explode('/', str_replace(array('/','\\'), '/', substr($path, 8)));
        $parts = array_values(array_filter($parts, array(__CLASS__, 'concatPharParts')));

        array_walk($parts, array(__CLASS__, 'resolvePharParentPath'), $parts);

        if (file_exists($realPath = 'phar:///' . implode('/', $parts))) {
            return $realPath;
        }
    }
510487
protected function _getRealAppPath()
    {
        $path = realpath(APP);
        if (substr($path, -1, 1) !== DS) {
            $path .= DS;
        }

        return $path;
    }