public static function rewrite($originalResource, string $originalDir = ''): string
    {
        static $appDir, $cacheDir, $debug;
        if ($appDir === null) {
            extract(self::$options, EXTR_IF_EXISTS);
        }

        $resource = (string) $originalResource;
        if ($resource[0] !== '/') {
            $shouldCheckExistence = true;
            $resource
                =  PathResolver::realpath($resource, $shouldCheckExistence)
                ?: PathResolver::realpath("{$originalDir}/{$resource}", $shouldCheckExistence)
                ?: $originalResource;
        }
        $cachedResource = self::$cachePathManager->getCachePathForResource($resource);

        // If the cache is disabled or no cache yet, then use on-fly method
        if (!$cacheDir || $debug || !file_exists($cachedResource)) {
            return self::PHP_FILTER_READ . self::$filterName . '/resource=' . $resource;
        }

        return $cachedResource;
    }
public static function rewrite($originalResource, string $originalDir = ''): string
    {
        static $appDir, $cacheDir, $debug;
        if ($appDir === null) {
            extract(self::$options, EXTR_IF_EXISTS);
        }

        $resource = (string) $originalResource;
        if ($resource[0] !== '/') {
            $shouldCheckExistence = true;
            $resource
                =  PathResolver::realpath($resource, $shouldCheckExistence)
                ?: PathResolver::realpath("{$originalDir}/{$resource}", $shouldCheckExistence)
                ?: $originalResource;
        }
        $cachedResource = self::$cachePathManager->getCachePathForResource($resource);

        // If the cache is disabled or no cache yet, then use on-fly method
        if (!$cacheDir || $debug || !file_exists($cachedResource)) {
            return self::PHP_FILTER_READ . self::$filterName . '/resource=' . $resource;
        }

        return $cachedResource;
    }
public static function rewrite ( $ originalResource , string $ originalDir = '' ) : string { static $ appDir , $ cacheDir , $ debug ; if ( $ appDir === null ) { extract ( self :: $ options , EXTR_IF_EXISTS ) ; } $ resource = ( string ) $ originalResource ; if ( $ resource [ 0 ] !== '/' ) { $ shouldCheckExistence = true ; $ resource = PathResolver :: realpath ( $ resource , $ shouldCheckExistence ) ? : PathResolver :: realpath ( "{$originalDir}/{$resource}" , $ shouldCheckExistence ) ? : $ originalResource ; } $ cachedResource = self :: $ cachePathManager -> getCachePathForResource ( $ resource ) ; // If the cache is disabled or no cache yet, then use on-fly method if ( ! $ cacheDir || $ debug || ! file_exists ( $ cachedResource ) ) { return self :: PHP_FILTER_READ . self :: $ filterName . '/resource=' . $ resource ; } return $ cachedResource ; }
Replace source path with correct one

This operation can check for cache, can rewrite paths, add additional filters and much more

@param string $originalResource Initial resource to include
@param string $originalDir Path to the directory from where include was called for resolving relative resources
Replace source path with correct one