8000 removed deprecated asset feature by fabpot · Pull Request #13666 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

removed deprecated asset feature #13666

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

Merged
merged 2 commits into from
Feb 12, 2015
Merged
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
69 changes: 2 additions & 67 deletions src/Symfony/Bridge/Twig/Extension/AssetExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Bridge\Twig\Extension;

use Symfony\Component\Asset\Packages;
use Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy;

/**
* Twig extension for the Symfony Asset component.
Expand All @@ -22,16 +21,10 @@
class AssetExtension extends \Twig_Extension
{
private $packages;
private $foundationExtension;

/**
* Passing an HttpFoundationExtension instance as a second argument must not be relied on
* as it's only there to maintain BC with older Symfony version. It will be removed in 3.0.
*/
public function __construct(Packages $packages, HttpFoundationExtension $foundationExtension = null)
public function __construct(Packages $packages)
{
$this->packages = $packages;
$this->foundationExtension = $foundationExtension;
}

/**
Expand All @@ -42,7 +35,6 @@ public function getFunctions()
return array(
new \Twig_SimpleFunction('asset', array($this, 'getAssetUrl')),
new \Twig_SimpleFunction('asset_version', array($this, 'getAssetVersion')),
new \Twig_SimpleFunction('assets_version', array($this, 'getAssetsVersion')),
);
}

Expand All @@ -57,20 +49,8 @@ public function getFunctions()
*
* @return string The public path of the asset
*/
public function getAssetUrl($path, $packageName = null, $absolute = false, $version = null)
public function getAssetUrl($path, $packageName = null)
{
// BC layer to be removed in 3.0
if (2 < $count = func_num_args()) {
trigger_error('Generating absolute URLs with the Twig asset() function was deprecated in 2.7 and will be removed in 3.0. Please use absolute_url() instead.', E_USER_DEPRECATED);
if (4 === $count) {
trigger_error('Forcing a version with the Twig asset() function was deprecated in 2.7 and will be removed in 3.0.', E_USER_DEPRECATED);
}

$args = func_get_args();

return $this->getLegacyAssetUrl($path, $packageName, $args[2], isset($args[3]) ? $args[3] : null);
}

return $this->packages->getUrl($path, $packageName);
}

Expand All @@ -87,51 +67,6 @@ public function getAssetVersion($path, $packageName = null)
return $this->packages->getVersion($path, $packageName);
}

public function getAssetsVersion($packageName = null)
{
trigger_error('The Twig assets_version() function was deprecated in 2.7 and will be removed in 3.0. Please use asset_version() instead.', E_USER_DEPRECATED);

return $this->packages->getVersion('/', $packageName);
}

private function getLegacyAssetUrl($path, $packageName = null, $absolute = false, $version = null)
{
if ($version) {
$package = $this->packages->getPackage($packageName);

$v = new \ReflectionProperty($package, 'versionStrategy');
$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));
}

try {
$url = $this->packages->getUrl($path, $packageName);
} catch (\Exception $e) {
if ($version) {
$v->setValue($package, $currentVersionStrategy);
}

throw $e;
}

if ($version) {
$v->setValue($package, $currentVersionStrategy);
}

if ($absolute) {
return $this->foundationExtension->generateAbsoluteUrl($url);
}

return $url;
}

/**
* Returns the name of the extension.
*
Expand Down
40 changes: 0 additions & 40 deletions src/Symfony/Bridge/Twig/Tests/Extension/AssetExtensionTest.php

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -53,44 +53,6 @@ public function getConfigTreeBuilder()
return $v;
})
->end()
->validate()
->ifTrue(function ($v) { return isset($v['templating']); })
->then(function ($v) {
if ($v['templating']['assets_version']
|| count($v['templating']['assets_base_urls']['http'])
|| count($v['templating']['assets_base_urls']['ssl'])
|| count($v['templating']['packages'])
) {
trigger_error('The assets settings under framework.templating are deprecated since version 2.7 and will be removed in 3.0. Use the framework.assets configuration key instead', E_USER_DEPRECATED);

// convert the old configuration to the new one
if (isset($v['assets'])) {
throw new LogicException('You cannot use assets settings under "templating.templating" and "assets" configurations in the same project.');
}

$v['assets'] = array(
'version' => $v['templating']['assets_version'],
'version_format' => $v['templating']['assets_version_format'],
'base_path' => '',
'base_urls' => array_values(array_unique(array_merge($v['templating']['assets_base_urls']['http'], $v['templating']['assets_base_urls']['ssl']))),
'packages' => array(),
);

foreach ($v['templating']['packages'] as $name => $config) {
$v['assets']['packages'][$name] = array(
'version' => (string) $config['version'],
'version_format' => $config['version_format'],
'base_path' => '',
'base_urls' => array_values(array_unique(array_merge($config['base_urls']['http'], $config['base_urls']['ssl']))),
);
}
}

unset($v['templating']['assets_version'], $v['templating']['assets_version_format'], $v['templating']['assets_base_urls'], $v['templating']['packages']);

return $v;
})
->end()
->children()
->scalarNode('secret')->end()
->scalarNode('http_method_override')
Expand Down Expand Up @@ -360,35 +322,14 @@ private function addRequestSection(ArrayNodeDefinition $rootNode)

private function addTemplatingSection(ArrayNodeDefinition $rootNode)
{
$organizeUrls = function ($urls) {
$urls += array(
'http' => array(),
'ssl' => array(),
);

foreach ($urls as $i => $url) {
if (is_integer($i)) {
if (0 === strpos($url, 'https://') || 0 === strpos($url, '//')) {
$urls['http'][] = $urls['ssl'][] = $url;
} else {
$urls['http'][] = $url;
}
unset($urls[$i]);
}
}

return $urls;
};

$rootNode
->children()
->arrayNode('templating')
->info('templating configuration')
->canBeUnset()
->children()
->scalarNode('assets_version')->defaultNull()->info('Deprecated since 2.7, will be removed in 3.0. Use the new assets entry instead.')->end()
->scalarNode('assets_version_format')->defaultValue('%%s?%%s')->info('Deprecated since 2.7, will be removed in 3.0. Use the new assets entry instead.')->end()
->scalarNode('hinclude_default_template')->defaultNull()->end()
->scalarNode('cache')->end()
->arrayNode('form')
->addDefaultsIfNotSet()
->fixXmlConfig('resource')
Expand All @@ -406,31 +347,6 @@ private function addTemplatingSection(ArrayNodeDefinition $rootNode)
->end()
->end()
->end()
->fixXmlConfig('assets_base_url')
->children()
->arrayNode('assets_base_urls')
->info('Deprecated since 2.7, will be removed in 3.0. Use the new assets entry instead.')
->performNoDeepMerging()
->addDefaultsIfNotSet()
->beforeNormalization()
->ifTrue(function ($v) { return !is_array($v); })
->then(function ($v) { return array($v); })
->end()
->beforeNormalization()
->always()
->then($organizeUrls)
->end()
->children()
->arrayNode('http')
->prototype('scalar')->end()
->end()
->arrayNode('ssl')
->prototype('scalar')->end()
->end()
->end()
->end()
->scalarNode('cache')->end()
->end()
->fixXmlConfig('engine')
->children()
->arrayNode('engines')
Expand All @@ -454,40 +370,6 @@ private function addTemplatingSection(ArrayNodeDefinition $rootNode)
->prototype('scalar')->end()
->end()
->end()
->fixXmlConfig('package')
->children()
->arrayNode('packages')
->info('Deprecated since 2.7, will be removed in 3.0. Use the new assets entry instead.')
->useAttributeAsKey('name')
->prototype('array')
->fixXmlConfig('base_url')
->children()
->scalarNode('version')->defaultNull()->end()
->scalarNode('version_format')->defaultValue('%%s?%%s')->end()
->arrayNode('base_urls')
->performNoDeepMerging()
->addDefaultsIfNotSet()
->beforeNormalization()
->ifTrue(function ($v) { return !is_array($v); })
->then(function ($v) { return array($v); })
->end()
->beforeNormalization()
->always()
->then($organizeUrls)
->end()
->children()
->arrayNode('http')
->prototype('scalar')->end()
->end()
->arrayNode('ssl')
->prototype('scalar')->end()
->end()
->end()
->end()
->end()
->end()
->end()
->end()
->end()
->end()
;
Expand Down
Loading
0