1<?php 2 3/* 4 * This file is part of the Symfony package. 5 * 6 * (c) Fabien Potencier <fabien@symfony.com> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12namespace Symfony\Bundle\FrameworkBundle\Templating\Helper; 13 14use Symfony\Component\Asset\Packages; 15use Symfony\Component\Templating\Helper\Helper; 16 17/** 18 * AssetsHelper helps manage asset URLs. 19 * 20 * @author Fabien Potencier <fabien@symfony.com> 21 */ 22class AssetsHelper extends Helper 23{ 24 private $packages; 25 26 public function __construct(Packages $packages) 27 { 28 $this->packages = $packages; 29 } 30 31 /** 32 * Returns the public url/path of an asset. 33 * 34 * If the package used to generate the path is an instance of 35 * UrlPackage, you will always get a URL and not a path. 36 * 37 * @param string $path A public path 38 * @param string $packageName The name of the asset package to use 39 * 40 * @return string The public path of the asset 41 */ 42 public function getUrl($path, $packageName = null) 43 { 44 return $this->packages->getUrl($path, $packageName); 45 } 46 47 /** 48 * Returns the version of an asset. 49 * 50 * @param string $path A public path 51 * @param string $packageName The name of the asset package to use 52 * 53 * @return string The asset version 54 */ 55 public function getVersion($path, $packageName = null) 56 { 57 return $this->packages->getVersion($path, $packageName); 58 } 59 60 /** 61 * {@inheritdoc} 62 */ 63 public function getName() 64 { 65 return 'assets'; 66 } 67} 68