10000 [FrameworkBundle] Use proper class to fetch $versionStrategy property by dosten · Pull Request #17298 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
10000

[FrameworkBundle] Use proper class to fetch $versionStrategy property #17298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/Symfony/Bridge/Twig/Extension/AssetExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,16 @@ private function getLegacyAssetUrl($path, $packageName = null, $absolute = false
{
if ($version) {
$package = $this->packages->getPackage($packageName);
$class = new \ReflectionClass($package);

while ('Symfony\Component\Asset\Package' !== $class->getName()) {
$class = $class->getParentClass();
}

$v = $class->getProperty('versionStrategy');
$v = new \ReflectionProperty('Symfony\Component\Asset\Package', 'versionStrategy');
$v->setAccessible(true);

$currentVersionStrategy = $v->getValue($package);

if (property_exists($currentVersionStrategy, 'format')) {
$f = new \ReflectionProperty($currentVersionStrategy, 'format');
$f->setAccessible(true);

$format = $f->getValue($currentVersionStrategy);

$v->setValue($package, new StaticVersionStrategy($version, $format));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,14 @@ private function getLegacyAssetUrl($path, $packageName = null, $version = null)
if ($version) {
$package = $this->packages->getPackage($packageName);

$v = new \ReflectionProperty($package, 'versionStrategy');
$v = new \ReflectionProperty('Symfony\Component\Asset\Package', 'versionStrategy');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please also update the Twig extension to use the same way

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stof Done

$v->setAccessible(true);

$currentVersionStrategy = $v->getValue($package);

$f = new \ReflectionProperty($currentVersionStrategy, 'format');
$f->setAccessible(true);

$format = $f->getValue($currentVersionStrategy);

$v->setValue($package, new StaticVersionStrategy($version, $format));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Symfony\Bundle\FrameworkBundle\Templating\Helper\AssetsHelper;
use Symfony\Component\Asset\Package;
use Symfony\Component\Asset\Packages;
use Symfony\Component\Asset\PathPackage;
use Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy;

class AssetsHelperTest extends \PHPUnit_Framework_TestCase
Expand All @@ -23,11 +24,14 @@ class AssetsHelperTest extends \PHPUnit_Framework_TestCase
*/
public function testLegacyGetUrl()
{
$package = new Package(new StaticVersionStrategy('22', '%s?version=%s'));
$packages = new Packages($package);
$versionStrategy = new StaticVersionStrategy('22', '%s?version=%s');
$package = new Package($versionStrategy);
$imagePackage = new PathPackage('images', $versionStrategy);
$packages = new Packages($package, array('images' => $imagePackage));
$helper = new AssetsHelper($packages);

$this->assertEquals('me.png?version=42', $helper->getUrl('me.png', null, '42'));
$this->assertEquals('/images/me.png?version=42', $helper->getUrl('me.png', 'images', '42'));
}

/**
Expand Down
0