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;
    }