Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
47 changed files
with
1,605 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bridge\Twig\Extension; | ||
|
||
use Symfony\Component\Asset\Packages; | ||
|
||
/** | ||
* Twig extension for the Symfony Asset component. | ||
* | ||
* @author Fabien Potencier <fabien@symfony.com> | ||
*/ | ||
class AssetExtension extends \Twig_Extension | ||
{ | ||
private $packages; | ||
|
||
public function __construct(Packages $packages) | ||
{ | ||
$this->packages = $packages; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getFunctions() | ||
{ | ||
return array( | ||
new \Twig_SimpleFunction('asset_path', array($this, 'getAssetPath')), | ||
new \Twig_SimpleFunction('asset_version', array($this, 'getAssetVersion')), | ||
); | ||
} | ||
|
||
/** | ||
* Returns the public path of an asset. | ||
* | ||
* If the package used to generate the path is an instance of | ||
* UrlPackage, you will always get a URL and not a path. | ||
* | ||
* @param string $path A public path | ||
* @param string $packageName The name of the asset package to use | ||
* | ||
* @return string The public path of the asset | ||
*/ | ||
public function getAssetPath($path, $packageName = null) | ||
{ | ||
return $this->packages->getUrl($path, $packageName); | ||
} | ||
|
||
/** | ||
* Returns the version of an asset. | ||
* | ||
* @param string $path A public path | ||
* @param string $packageName The name of the asset package to use | ||
* | ||
* @return string The asset version | ||
*/ | ||
public function getAssetVersion($path, $packageName = null) | ||
{ | ||
return $this->packages->getVersion($path, $packageName); | ||
} | ||
|
||
/** | ||
* Returns the name of the extension. | ||
* | ||
* @return string The extension name | ||
*/ | ||
public function getName() | ||
{ | ||
return 'asset'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/Symfony/Bundle/FrameworkBundle/Resources/config/assets.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?xml version="1.0" ?> | ||
|
||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
|
||
<services> | ||
|
||
<service id="assets.packages" class="Symfony\Component\Asset\Packages"> | ||
<argument /> <!-- default package --> | ||
<argument type="collection" /> <!-- named packages --> | ||
</service> | ||
|
||
<service id="assets.context" class="Symfony\Component\Asset\Context\RequestStackContext"> | ||
<argument type="service" id="request_stack" /> | ||
</service> | ||
|
||
<service id="assets.path_package" class="Symfony\Component\Asset\PathPackage" abstract="true"> | ||
<argument /> <!-- base path --> | ||
<argument type="service" /> <!-- version strategy --> | ||
<call method="setContext"> | ||
<argument type="service" id="assets.context" /> | ||
</call> | ||
</service> | ||
|
||
<service id="assets.url_package" class="Symfony\Component\Asset\UrlPackage" abstract="true"> | ||
<argument /> <!-- base URLs --> | ||
<argument type="service" /> <!-- version strategy --> | ||
<call method="setContext"> | ||
<argument type="service" id="assets.context" /> | ||
</call> | ||
</service> | ||
|
||
<service id="assets.static_version_strategy" class="Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy" abstract="true"> | ||
<argument /> <!-- version --> | ||
<argument /> <!-- format --> | ||
</service> | ||
|
||
<service id="assets.empty_version_strategy" class="Symfony\Component\Asset\VersionStrategy\EmptyVersionStrategy" public="false" /> | ||
|
||
</services> | ||
</container> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.