Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit98cb838

Browse files
committed
Added the assets helper again
1 parent3040977 commit98cb838

File tree

3 files changed

+112
-2
lines changed

3 files changed

+112
-2
lines changed

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/templating_php.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@
3434

3535
<serviceid="templating.helper.assets"class="Symfony\Bundle\FrameworkBundle\Templating\Helper\AssetsHelper">
3636
<tagname="templating.helper"alias="assets" />
37-
<argument /><!-- default package-->
38-
<argumenttype="collection" /><!-- named packages-->
37+
<argument /><!-- packages-->
3938
</service>
4039

4140
<serviceid="templating.helper.actions"class="Symfony\Bundle\FrameworkBundle\Templating\Helper\ActionsHelper">
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
12+
namespaceSymfony\Bundle\FrameworkBundle\Templating\Helper;
13+
14+
useSymfony\Component\Asset\Packages;
15+
useSymfony\Component\Templating\Helper\Helper;
16+
17+
/**
18+
* AssetsHelper helps manage asset URLs.
19+
*
20+
* @author Fabien Potencier <fabien@symfony.com>
21+
*/
22+
class AssetsHelperextends Helper
23+
{
24+
private$packages;
25+
26+
publicfunction__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+
publicfunctiongetUrl($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+
publicfunctiongetVersion($path,$packageName =null)
56+
{
57+
return$this->packages->getVersion($path,$packageName);
58+
}
59+
60+
/**
61+
* {@inheritdoc}
62+
*/
63+
publicfunctiongetName()
64+
{
65+
return'assets';
66+
}
67+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
12+
namespaceSymfony\Bundle\FrameworkBundle\Tests\Templating\Helper;
13+
14+
useSymfony\Bundle\FrameworkBundle\Templating\Helper\AssetsHelper;
15+
useSymfony\Component\Asset\Package;
16+
useSymfony\Component\Asset\Packages;
17+
useSymfony\Component\Asset\VersionStrategy\StaticVersionStrategy;
18+
19+
class AssetsHelperTestextends \PHPUnit_Framework_TestCase
20+
{
21+
private$helper;
22+
23+
protectedfunctionsetUp()
24+
{
25+
$fooPackage =newPackage(newStaticVersionStrategy('42','%s?v=%s'));
26+
$barPackage =newPackage(newStaticVersionStrategy('22','%s?%s'));
27+
28+
$packages =newPackages($fooPackage, ['bar' =>$barPackage]);
29+
30+
$this->helper =newAssetsHelper($packages);
31+
}
32+
33+
publicfunctiontestGetUrl()
34+
{
35+
$this->assertEquals('me.png?v=42',$this->helper->getUrl('me.png'));
36+
$this->assertEquals('me.png?22',$this->helper->getUrl('me.png','bar'));
37+
}
38+
39+
publicfunctiontestGetVersion()
40+
{
41+
$this->assertEquals('42',$this->helper->getVersion('/'));
42+
$this->assertEquals('22',$this->helper->getVersion('/','bar'));
43+
}
44+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp