Phrozn\Site\View\OutputPath\Base::getRelativeFile PHP Method

getRelativeFile() protected method

Detect relative file path with respect to $base folder
protected getRelativeFile ( string $base = '', boolean $prepend = true ) : string
$base string Base folder name from which to start
$prepend boolean Whether to prepend base folder name to result
return string
    protected function getRelativeFile($base = '', $prepend = true)
    {
        // find file path w/o extension
        $inputFile = $this->getInputFileWithoutExt();
        $inputRoot = $this->getView()->getInputRootDir();
        // Normalize direcotry separators so comparison works
        $trans = array('/' => DIRECTORY_SEPARATOR, '\\' => DIRECTORY_SEPARATOR);
        $inputFile = strtr($inputFile, $trans);
        $inputRoot = strtr($inputRoot, $trans);
        // Remove the input root from the input filename
        $inputFile = str_replace($inputRoot, '', $inputFile);
        // find relative path, wrt to output root dir
        if ($base) {
            $pos = strpos($inputFile, $base);
            if ($pos !== false) {
                $inputFile = substr($inputFile, $pos + ($prepend ? 0 : 1 + strlen($base)));
            }
        }
        return $inputFile;
    }