JBZoo\Utils\FS::getRelative PHP Method

getRelative() public static method

Find relative path of file (remove root part)
public static getRelative ( string $filePath, string | null $rootPath = null, string $forceDS = DIRECTORY_SEPARATOR, boolean $toRealpath = true ) : mixed
$filePath string
$rootPath string | null
$forceDS string
$toRealpath boolean
return mixed
    public static function getRelative($filePath, $rootPath = null, $forceDS = DIRECTORY_SEPARATOR, $toRealpath = true)
    {
        // Cleanup file path
        if ($toRealpath && !self::isReal($filePath)) {
            $filePath = self::real($filePath);
        }
        $filePath = self::clean($filePath, $forceDS);
        // Cleanup root path
        $rootPath = $rootPath ?: Sys::getDocRoot();
        if ($toRealpath && !self::isReal($rootPath)) {
            $rootPath = self::real($rootPath);
        }
        $rootPath = self::clean($rootPath, $forceDS);
        // Remove root part
        $relPath = preg_replace('#^' . preg_quote($rootPath) . '#i', '', $filePath);
        $relPath = ltrim($relPath, $forceDS);
        return $relPath;
    }

Usage Example

コード例 #1
0
ファイル: Leafo.php プロジェクト: jbzoo/less
 /**
  * {@inheritdoc}
  */
 public function setImportPath($fullPath, $relPath = null)
 {
     $this->_initCompiler();
     if (!FS::isDir($fullPath)) {
         throw new Exception('Undefined import path: ' . $fullPath);
     }
     $fullPath = FS::getRelative($fullPath, $this->_options->get('root_path'));
     $this->_compiler->addImportDir($fullPath);
 }
All Usage Examples Of JBZoo\Utils\FS::getRelative