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;
    }
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;
    }
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 ; }
Get the URL for a given asset name.

Takes an build filename, and returns the URL
to that build file.

@param string $file The build file that you want a URL for.
@param bool|array $full Whether or not the URL should have the full base path.
@return string The generated URL.
@throws RuntimeException when the build file does not exist.
Get the URL for a given asset name .