Get list of relative path to file or directory

@param string $source (example: "default:*.txt")
@return null|string
6245
public function relGlob($source)
    {
        $list = (array)$this->glob($source);
        foreach ($list as $key => $item) {
            $list[$key] = FS::getRelative($item, $this->root, '/');
        }

        return $list;
    }
81382
public static function directoryDiff($source, $target)
    {
        $sourceFiles = self::globr($source, '*');
        $targetFiles = self::globr($target, '*');

        $sourceFiles = array_map(function ($file) use ($source) {
            return str_replace($source, '', $file);
        }, $sourceFiles);

        $targetFiles = array_map(function ($file) use ($target) {
            return str_replace($target, '', $file);
        }, $targetFiles);

        $diff = array_diff($targetFiles, $sourceFiles);

        return array_values($diff);
    }
40367
public function url($source, $full = true)
    {
        $details = explode('?', $source);

        $path = $details[0];
        $path = $this->cleanPathInternal($path);
        $path = $this->getUrlPath($path, true);

        if (!empty($path)) {
            if (isset($details[1])) {
                $path .= '?' . $details[1];
            }

            $path = '/' . $path;
            return $full ? Url::root() . $path : $path;
        }

        return null;
    }
1144048
public static function getDOMDocument($source) 
    {
        if ($source instanceof DOMDOCUMENT) {
            return $source;
        }
        $source = self::getDocumentID($source);
        return $source
        ? self::$documents[$id]['document']
        : null;
    }
192934
public static function relativepath(String $string) : String
    {
        return str_replace(REAL_BASE_DIR, NULL, self::originpath($string));
    }
1269636
public function resolvePath (string $source, string $target) : string
    {
        $sourceDirs = $this->toDirectoryFragments(\dirname($source));
        $targetFileName = \basename($target);

        // if relative path is absolute, just return the absolute path
        if ("/" === \substr($target, 0, 1))
        {
            return $target;
        }

        // strip leading "./"
        if ("./" === \substr($target, 0, 2))
        {
            $target = \substr($target, 2);
        }

        $targetDirs = $this->toDirectoryFragments(\dirname($target));

        // if the relative dirs are empty (it is just a file name), use the same directory
        if (empty($targetDirs))
        {
            return $this->buildFilePath($sourceDirs, $targetFileName);
        }

        // strip leading "../../" from the beginning of the relative dir and simultaneously from the end of the source dir
        while (!empty($targetDirs) && ".." === $targetDirs[0])
        {
            \array_pop($sourceDirs);
            \array_shift($targetDirs);
        }

        return $this->buildFilePath(
            \array_merge($sourceDirs, $targetDirs),
            $targetFileName
        );
    }
1162040
public function get_file_reference($source) {
        global $USER;
        list($type, $fileid, $filename) = $this->split_part($source);
        $reference = new stdClass();
        $reference->fileid = $fileid;
        $reference->filename = $filename;
        $reference->userid = $USER->id;
        $reference->downloadurl = '';
        if (optional_param('usefilereference', false, PARAM_BOOL)) {
            try {
                $shareinfo = $this->boxnetclient->share_file($reference->fileid);
            } catch (moodle_exception $e) {
                throw new repository_exception('cannotcreatereference', 'repository_boxnet');
            }
            $reference->downloadurl = $shareinfo->download_url;
        }
        return serialize($reference);
    }
610247
public function loadResource($source = null)
    {

        $routes     = array();
        $source     = $this->resolveResorceSource($source);
        $extension  = Path::getExtension($source);

        if (file_exists($source)) {
            $content = File::load($source);
            if ($extension == 'yml') {
                $array  = Yaml::parse($content);
            } elseif ($extension == 'json') {
                $array  = json_decode($content, true);
            } else {
                throw new \Exception("Unsupported routing file type. Routes can only be loaded from yml or json files");
            }

            if (is_array($array)) {

                if (isset($array['imports'])) {
                    foreach ($array['imports'] as $import) {
                        if (isset($import['resource'])) {
                            $extraSource = $this->resolveResorceSource($import['resource']);
                            foreach ($this->loadResource($import['resource']) as $name => $route) {
                                $routes[$name] = $route;
                            }
                        }
                    }
                }

                if (isset($array['routes'])) {
                    foreach ($array['routes'] as $name => $route) {
                        $routes[$name] = $route;
                    }
                }
            }
        }

        $this->resource = $routes;

        return $routes;
    }
118788
public function relativePath($reset = true)
    {
        $output = preg_replace('|^' . preg_quote(GRAV_ROOT, '|') . '|', '', $this->get('filepath'));

        $locator = Grav::instance()['locator'];
        if ($locator->isStream($output)) {
            $output = $locator->findResource($output, false);
        }

        if ($reset) {
            $this->reset();
        }

        return str_replace(GRAV_ROOT, '', $output);
    }
860769
public function getPaths($extension = null)
	{
		if (isset($extension))
		{
			if (isset($this->paths[$extension]))
			{
				return $this->paths[$extension];
			}

			return;
		}

		return $this->paths;
	}
460643
private function get_relative_path( $path ) {
            $module_root_dir = $this->get_module_root_dir_path();
            if ( 0 === strpos( $path, $module_root_dir ) ) {
                $path = substr( $path, strlen( $module_root_dir ) );
            }

            return $path;
        }
922746
public function getList(string $path)
    {
        $entity = $this->getEntity($path);

        if (null !== $entity && $entity->file_exists() && $entity->is_dir()) {
            $files = [];
            $changes = $this->getChanges();
            $own = $changes->own($path);

            if (!($entity instanceof VirtualInterface)) {
                $directory = $this->getRoot();
                $directoryPath = $directory->path().'/'.$path;

                $dirHandler = opendir($directoryPath);
                if ($dirHandler) {
                    while (true) {
                        $file = readdir($dirHandler);
                        if (false === $file) {
                            break;
                        } elseif ('.' == $file || '..' == $file) {
                            continue;
                        }

                        $changesKey = ($path ? $path.'/' : '').$file;
                        if (isset($own[$changesKey])) {
                            continue;
                        }
                        $files[$changesKey] = Entity::newInstance($changesKey);
                    }
                    closedir($dirHandler);
                }
            }

            foreach ($own as $changesKey => $file) {
                /* @var $file EntityInterface */
                if ($file instanceof DeletedInterface) {
                    unset($own[$changesKey]);
                }
            }

            $mergedFiles = array_merge($files, $own);
            ksort($mergedFiles);

            $result = array_values($mergedFiles);
        } else {
            $result = null;
        }

        return $result;
    }
902464
protected function getPackageMigrations($source)
	{
		$files = array_filter($this->files->files($source), function($file)
		{
			return ! starts_with($file, '.');
		});

		sort($files);

		return $files;
	}
1106911
protected function evaluatePath($source)
    {
        static $theme;

        // Make theme to use few features.
        if ( ! $theme)
        {
            $theme = \App::make('theme');
        }

        // Switch path to another theme.
        if ( ! is_bool($this->usePath) and $theme->exists($this->usePath))
        {
            $currentTheme = $theme->getThemeName();

            $source = str_replace($currentTheme, $this->usePath, $source);
        }

        return $source;
    }
291398
public function get_file_reference($source) {
        // Internally we store serialized value but user input is json-encoded for security reasons.
        $ref = json_decode(base64_decode($source));
        $filename  = clean_param($ref->filename, PARAM_FILE);
        $url = clean_param($ref->url, PARAM_URL);
        return base64_encode(serialize((object)array('url' => $url, 'filename' => $filename)));
    }
1208185
public function glob($source)
    {
        list(, $paths, $path) = $this->parse($source);
        return $this->find($paths, $path, true);
    }
350240
public function cdn($source)
	{
		$url = str_ireplace($this->public_path, '', $this->assets_path . '/' . ltrim($source, '/'));
		$url = $this->cdn ? $this->cdn . $url : $url;
		return $url;
	}