AssetCompress\View\Helper\AssetCompressHelper::url PHP Method

url() public method

Takes an build filename, and returns the URL to that build file.
public url ( string $file = null, boolean | array $full = false ) : string
$file string The build file that you want a URL for.
$full boolean | array Whether or not the URL should have the full base path.
return string The generated URL.
    public function url($file = null, $full = false)
    {
        $collection = $this->collection();
        if (!$collection->contains($file)) {
            throw new RuntimeException('Cannot get URL for build file that does not exist.');
        }
        $options = $full;
        if (!is_array($full)) {
            $options = ['full' => $full];
        }
        $options += ['full' => false];
        $target = $collection->get($file);
        $type = $target->ext();
        $config = $this->assetConfig();
        $baseUrl = $config->get($type . '.baseUrl');
        $devMode = Configure::read('debug');
        // CDN routes.
        if ($baseUrl && !$devMode) {
            return $baseUrl . $this->_getBuildName($target);
        }
        $root = str_replace('\\', '/', WWW_ROOT);
        $path = str_replace('\\', '/', $target->outputDir());
        $path = str_replace($root, '/', $path);
        $route = null;
        if (!$devMode) {
            $path = rtrim($path, '/') . '/';
            $route = $path . $this->_getBuildName($target);
        }
        if ($devMode || $config->general('alwaysEnableController')) {
            $route = $this->_getRoute($target, $path);
        }
        if (DS === '\\') {
            $route = str_replace(DS, '/', $route);
        }
        if ($options['full']) {
            $base = Router::fullBaseUrl();
            return $base . $route;
        }
        return $route;
    }