Build link to local asset.

Detects packages links.

@param  string $asset
@param  string $dir
@return string the link
2389
protected function buildLocalLink($asset, $dir)
    {
        $collection = $this->assetIsFromCollection($asset);
        if ($collection !== false) {
            return $this->collections_dir.'/'.$collection[0].'/'.ltrim($dir, '/').'/'.$collection[1];
        }

        return parent::buildLocalLink($asset, $dir);
    }
118338
public function assetUrl(string $asset): string
    {
        $file = $this->resourcesFolder() . $asset;

        // Add the file's modification time to the URL, so we can set long expiry cache headers.
        $hash = filemtime($file);

        return route('module', [
            'module' => $this->name(),
            'action' => 'asset',
            'asset'  => $asset,
            'hash'   => $hash,
        ]);
    }
48580
protected function getAssets(Composer $composer, $assetDir, array $packages)
    {
        $installationManager = $composer->getInstallationManager();
        $configPackages = $this->config->getArray('enable-packages');
        $assets = array();

        foreach ($packages as $package) {
            $filename = AssetUtil::getPath($installationManager, $this->assetManager, $package, $configPackages);

            if (null !== $filename) {
                list($packageName, $packagePath) = $this->getMockPackagePath($package, $assetDir, $filename);
                $assets[$packageName] = $packagePath;
            }
        }

        $assetsEvent = new GetAssetsEvent($assetDir, $packages, $assets);
        $composer->getEventDispatcher()->dispatch(FoxyEvents::GET_ASSETS, $assetsEvent);

        return $assetsEvent->getAssets();
    }
360145
public function prependJs($asset)
	{
		if(is_array($asset))
		{
			foreach(array_reverse($asset) as $a)
				$this->prependJs($a);

			return $this;
		}

		if( ! $this->isRemoteLink($asset))
			$asset = $this->buildLocalLink($asset, $this->js_dir);

		if( ! in_array($asset, $this->js))
			array_unshift($this->js, $asset);

		return $this;
	}
186019
public function linkAsset($url, $title = null, $attributes = array(), $secure = null)
	{
		$url = $this->url->asset($url, $secure);

		return $this->link($url, $title ?: $url, $attributes, $secure);
	}
1072661
public function addToPackages($dir)
    {
        $files = glob($dir.'/*');

        $packageViews = Config::get('cms.package-menus');

        if (is_null($packageViews)) {
            $packageViews = [];
        }

        foreach ($files as $view) {
            array_push($packageViews, $view);
        }

        return Config::set('cms.package-menus', $packageViews);
    }
223789
private function getAssetPath(AssetFileModel $asset)
    {
        if ($asset->getSource()->type != 'Local') {
            throw new Exception(Craft::t('Could not get asset upload path as source is not "Local"'));
        }

        $sourcePath = $asset->getSource()->settings['path'];
        $folderPath = $asset->getFolder()->path;

        return $sourcePath . $folderPath . $asset->filename;
    }
1055968
public function url($asset)
    {   
        $url = $this->parsePathAlias($asset, false);

        return $this->buildUrl($url);
    }
1263567
public static function addSystemScript($script, $dir = 'js')
	{
		if ($dir != 'js')
		{
			$script = $dir . '/' . $script;
		}

		$asset = new Javascript('system', $script);

		if ($asset->exists())
		{
			if ($document = self::app('document'))
			{
				$document->addScript($asset->link());
			}
		}
	}
131027
public function findFallbackAsset($asset, $Folder = null)
    {
        $folderEmpty = empty($Folder);
        $folderAllowFallback = ! empty($Folder) && $Folder->getFallback();

        if ($folderEmpty || $folderAllowFallback) {
            $fallbackPath = $this->engine->getDirectory();

            $fallbackPath = $this->removeViewFromPath($fallbackPath);
            if (file_exists($fallbackPath . DS . $asset)) {
                $this->createSymlink($fallbackPath);

                return '/' . $this->assetDir . '/' . $this->asset['asset'];
            }
        }

        return false;
    }
858764
public function webpackAsset($asset)
    {
        $asset_id        = $this->public_path . '/' . Compiler::getAliasId($asset);
        $full_asset_path = $this->web_dir . '/' . $asset_id;

        return [
            'js'  => file_exists($full_asset_path . '.js')
                ? $asset_id . '.js?' . filemtime($full_asset_path . '.js')
                : false,
            'css' => file_exists($full_asset_path . '.css')
                ? $asset_id . '.css?' . filemtime($full_asset_path . '.css')
                : false,
        ];
    }
416087
private function build_asset_args( $asset ) {

		// setup default args for array type includes
		$args = array(
			'src'       => $asset,
			'deps'      => array(),
			'ver'       => false,
			'in_footer' => false,
			'media'     => false,
		);

		if ( is_array( $asset ) ) {
			$args = array_merge( $args, $asset );
		}

		// add uix dep
		$args['deps'][] = 'uix';

		return $args;
	}
700490
public function asset_url($path)
    {
        // iframe content can't be in a different domain
        // @TODO: check if assests are on a different domain

        if (!$this->assets_path || in_array($path[0], array('?', '/', '.')) || strpos($path, '://')) {
            return $path;
        }

        return $this->assets_path . $path;
    }
189941
public static function route_get_local_path($dir) {
        $uri = $_SERVER['REQUEST_URI'];     // /tsugi/lti/some/cool/stuff
        $root = $_SERVER['DOCUMENT_ROOT'];  // /Applications/MAMP/htdocs
        $cwd = $dir;                        // /Applications/MAMP/htdocs/tsugi/lti
        if ( strlen($cwd) < strlen($root) + 1 ) return false;
        $lwd = substr($cwd,strlen($root));  // /tsugi/lti
        if ( strlen($uri) < strlen($lwd) + 2 ) return false;
        $local = substr($uri,strlen($lwd)+1); // some/cool/stuff
        return $local;
    }
381668
public function addSysPath($assetUri)
    {
        if (static::isAbsoluteUrl($assetUri)) {
            return $assetUri;
        }

        $assetUri = trim(str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $assetUri), '/\\');
        $base     = rtrim($this->config->get('path.public'), '/\\');

        if (!$base) {
            return '/';
        }

        $match = '';

        // @see http://stackoverflow.com/a/6704596
        for ($i = strlen($base) - 1; $i >= 0; $i -= 1) {
            $chunk = substr($base, $i);
            $len   = strlen($chunk);

            if (substr($assetUri, 0, $len) == $chunk && $len > strlen($match)) {
                $match = $chunk;
            }
        }

        return $base . DIRECTORY_SEPARATOR . ltrim(substr($assetUri, strlen($match)), '/\\');
    }
1284736
def link_asset(url, link=true)
      if @sprockets_context
        # Getting the asset_path also links to the context.
        linked_url = @sprockets_context.asset_path(url)
      else
        # When compiling on the server, we don't use sprockets (atm), so the
        # context won't exist.  Typically compiling on the server is just used
        # to test, so we simply return the url.
        linked_url = url
      end

      last << url if link

      linked_url
    end
1084508
public function combineAssets(array $assets, $localPath = '')
    {
        // Short circuit if no assets actually provided
        if (empty($assets)) {
            return '';
        }
        $assetPath = !empty($localPath) ? $localPath : $this->assetPath;
        return Url::to(CombineAssets::combine($assets, $assetPath));
    }