Get the dirname

@param string $realpath The real path

@return string Return the symbolic path
353054
static function getSymbolicPath($realpath)
    {
        $root = $_SERVER['DOCUMENT_ROOT'];
        $script = $_SERVER['SCRIPT_FILENAME'];
        $root = str_replace('\\', '/', $root);
        $script = str_replace('\\', '/', $script);
        $realpath = str_replace('\\', '/', $realpath);
        
        $dir = str_replace($root, '', $script);
        $pos = false;
        $dir = self::getDir($dir);
        while (! empty($dir)) {
            $pos = strpos($realpath, $dir);
            if ($pos) {
                break;
            }
            $dir = self::getDir($dir);
        }
        if ($pos) {
            $realpath = $root . substr($realpath, $pos);
        }
        return $realpath;
    }
797143
protected static String getName(String fullPath)
   {
      int sl = fullPath.lastIndexOf('/');
      return sl >= 0 ? fullPath.substring(sl + 1) : fullPath;
   }
554953
protected function _findPath($path)
    {
        $path = $this->_unifyPath($path);
        $dirs = $this->_dirs;

        $file = null;

        foreach ($dirs as $dir) {
            if (is_readable(realpath($dir.DS.$path))) {
                $file = $dir.DS.$path;
                break;
            }
        }

        return $file;
    }
412524
private function packagePath(string $relativePath): string
    {
    	$packagePath = rtrim(str_replace('/', DIRECTORY_SEPARATOR, $this->packagePath), DIRECTORY_SEPARATOR);
        $relativePath = ltrim(str_replace('/', DIRECTORY_SEPARATOR, $relativePath), DIRECTORY_SEPARATOR);

        return realpath($packagePath . DIRECTORY_SEPARATOR . $relativePath);
    }
640770
public static function realPath($path)
    {
        if (self::isPhar($path) === false) {
            return realpath($path);
        }

        preg_match('/^(phar:\/{0,2})?(.*)?/u', $path, $matches);

        $path = self::resolveRelativeToGlobal($matches[2]);
        $path = self::resolveDots($path);

        return self::PHAR_PREFIX . $path;
    }
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'];
	}
825428
public function realpath($path)
    {
        $path = str_replace('/', DS, trim($path));
        if (strpos($path, '..') === false) {
            if (!Folder::isAbsolute($path)) {
                $path = Folder::addPathElement($this->path, $path);
            }

            return $path;
        }
        $parts = explode(DS, $path);
        $newparts = array();
        $newpath = '';
        if ($path[0] === DS) {
            $newpath = DS;
        }

        while (($part = array_shift($parts)) !== null) {
            if ($part === '.' || $part === '') {
                continue;
            }
            if ($part === '..') {
                if (!empty($newparts)) {
                    array_pop($newparts);
                    continue;
                }

                return false;
            }
            $newparts[] = $part;
        }
        $newpath .= implode(DS, $newparts);

        return Folder::slashTerm($newpath);
    }
662619
public function getRealPath($path)
    {
        // 得到确定的path
        $path = $this->getPathFromUrl($path);
        $path = $this->safePath($path);
        
        // *nux系统上不存在的文件realpath() = false，因此先去存贮目录的真实路径
        $path = realpath($this->storageDir) . '/' . $path;
        
        return $path;
    }
412851
public function location($realpath = false)
    {
        try {
            if ($this->view->exists($this->content)) {
                return ($realpath) ? $this->view->getFinder()->find($this->content) : $this->content;
            }  
        } catch (\InvalidArgumentException $e) {
            return null;
        }
    }
357617
public function getProjectPath(string $filePath): string
    {
        $rootPath = $this->getRootApplicationDirectoryPathByFilePath($filePath);

        $path = rtrim($rootPath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
        $path .= implode(DIRECTORY_SEPARATOR, [
            'src',
            'Pyz',
            'Zed',
        ]);

        return rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
    }
1249106
public function getRealWritingFilePath($path, $rootDir)
    {
        $realDir = $this->getRealDir($path, $rootDir);

        if (!is_string($realDir)) {
            return false;
        }

        return $realDir . DIRECTORY_SEPARATOR . basename($path);
    }
687658
public function getDirName($path, $isFullPath = true, $useIsDir = true)
    {
        $dirName = preg_replace('/\/$/i', '', $path);
        $dirName = ($useIsDir && is_dir($dirName)) ? $dirName : pathinfo($dirName, PATHINFO_DIRNAME);

        if (!$isFullPath) {
            $pieces = explode('/', $dirName);
            $dirName = $pieces[count($pieces)-1];
        }

        return $dirName;
    }
505585
public static function dirname_r( $path, $count = 1 ){
    if ( $count > 1 ){
      return dirname(self::dirname_r( $path, --$count) );
    } else {
      return dirname( $path );
    }
	}
1051909
private function getMainWithHashedPaths(string $realPath): string
  {
    $main_js_file = self::getMainJsFileName($realPath);
    // Read the main file.
    $js = file_get_contents($main_js_file);
    if ($js===false) $this->logError("Unable to read file '%s'.", $realPath);

    // Extract paths from main.
    preg_match('/^(.*paths:[^{]*)({[^}]*})(.*)$/sm', $js, $matches);
    if (!isset($matches[2])) $this->logError("Unable to find paths in '%s'.", $realPath);

    // @todo Remove from paths files already combined.

    // Lookup table as paths in requirejs.config, however, keys and values are flipped.
    $paths = [];
    // Replace aliases to paths with aliases to paths with hashes (i.e. paths to minimized files).
    list($base_url, $aliases) = $this->extractPaths($main_js_file);
    if (isset($base_url) && isset($paths))
    {
      foreach ($aliases as $alias => $path)
      {
        $path_with_hash = $this->getPathInResourcesWithHash($base_url, $path);
        if (isset($path_with_hash))
        {
          $paths[$this->removeJsExtension($path_with_hash)] = $alias;
        }
      }
    }

    // Add paths from modules that conform to ADM naming convention to paths with hashes (i.e. path to minimized files).
    foreach ($this->getResourcesInfo() as $info)
    {
      // @todo Skip *.main.js files.

      // Test JS file is not already in paths, e.g. 'jquery': 'jquery/jquery'.
      if (!isset($paths[$this->removeJsExtension($info['path_name_in_sources_with_hash'])]))
      {
        if (isset($info['path_name_in_sources']))
        {
          $module                 = $this->getNamespaceFromResourceFilename($info['full_path_name']);
          $path_with_hash         = $this->getNamespaceFromResourceFilename($info['full_path_name_with_hash']);
          $paths[$path_with_hash] = $module;
        }
      }
    }

    // Convert the paths to proper JS code.
    $matches[2] = json_encode(array_flip($paths), JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
    array_shift($matches);
    $js = implode('', $matches);

    return $js;
  }
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);
    }
470872
public static function dirname($path)
    {
        if (strpos($path, '\\') === false) {
            return dirname($path);
        }
        return str_replace('/', '\\', dirname(str_replace('\\', '/', $path)));
    }
1211931
static public function getRelPath(string $fullPath): string {
        $contDir = RC::get('containerDir');
        if (!strpos($fullPath, $contDir) === 0) {
            throw new InvalidArgumentException('path is outside the container');
        }
        $contDir = preg_replace('|/$|', '', $contDir);
        return substr($fullPath, strlen($contDir) + 1);
    }