Skip to content

Commit 9d9f956

Browse files
committed
Merge branch '3.0'
* 3.0: (36 commits) Fixed form types in profiler [Process] Use stream based storage to avoid memory issues Fix upgrade guides concerning erroneous removal of assets helper [Process] Remove a misleading comment Fix markdown typo ChooseBaseUrl should return an index [Form] ChoiceType: Fix a notice when 'choices' normalizer is replaced Improve the phpdoc of SplFileInfo methods [Process] Use stream based storage to avoid memory issues [FrameworkBundle] Don't log twice with the error handler synchronize 2.8 and 3.0 upgrade files Remove useless is_object condition [Process] Fix typo, no arguments needed anymore [Serializer] Introduce constants for context keys Fixed the documentation of VoterInterface::supportsAttribute Fixed Bootstrap form theme form "reset" buttons Fixed the form profiler when using long form types [PropertyInfo] PhpDocExtractor: Fix a notice when the property doesn't exist Remove useless duplicated tests [FrameworkBundle] Optimize framework extension tests ...
2 parents c26cfcb + d7c3e91 commit 9d9f956

File tree

6 files changed

+128
-8
lines changed

6 files changed

+128
-8
lines changed

DependencyInjection/Compiler/AddConsoleCommandPass.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ public function process(ContainerBuilder $container)
3737
}
3838

3939
$class = $container->getParameterBag()->resolveValue($definition->getClass());
40-
$r = new \ReflectionClass($class);
41-
if (!$r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command')) {
40+
if (!is_subclass_of($class, 'Symfony\\Component\\Console\\Command\\Command')) {
4241
throw new \InvalidArgumentException(sprintf('The service "%s" tagged "console.command" must be a subclass of "Symfony\\Component\\Console\\Command\\Command".', $id));
4342
}
4443
$container->setAlias('console.command.'.strtolower(str_replace('\\', '_', $class)), $id);

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
<service id="templating.helper.assets" class="Symfony\Bundle\FrameworkBundle\Templating\Helper\AssetsHelper">
3636
<tag name="templating.helper" alias="assets" />
37-
<argument /> <!-- default package -->
38-
<argument type="collection" /> <!-- named packages -->
37+
<argument /> <!-- packages -->
3938
</service>
4039

4140
<service id="templating.helper.actions" class="Symfony\Bundle\FrameworkBundle\Templating\Helper\ActionsHelper">

Templating/Helper/AssetsHelper.php

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+
namespace Symfony\Bundle\FrameworkBundle\Templating\Helper;
13+
14+
use Symfony\Component\Asset\Packages;
15+
use Symfony\Component\Templating\Helper\Helper;
16+
17+
/**
18+
* AssetsHelper helps manage asset URLs.
19+
*
20+
* @author Fabien Potencier <fabien@symfony.com>
21+
*/
22+
class 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+
}

Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
abstract class FrameworkExtensionTest extends TestCase
2424
{
25+
private static $containerCache = array();
26+
2527
abstract protected function loadFromFile(ContainerBuilder $container, $file);
2628

2729
public function testFormCsrfProtection()
@@ -482,6 +484,10 @@ protected function createContainer(array $data = array())
482484

483485
protected function createContainerFromFile($file, $data = array())
484486
{
487+
$cacheKey = md5($file.serialize($data));
488+
if (isset(self::$containerCache[$cacheKey])) {
489+
return self::$containerCache[$cacheKey];
490+
}
485491
$container = $this->createContainer($data);
486492
$container->registerExtension(new FrameworkExtension());
487493
$this->loadFromFile($container, $file);
@@ -490,7 +496,7 @@ protected function createContainerFromFile($file, $data = array())
490496
$container->getCompilerPassConfig()->setRemovingPasses(array());
491497
$container->compile();
492498

493-
return $container;
499+
return self::$containerCache[$cacheKey] = $container;
494500
}
495501

496502
protected function createContainerFromClosure($closure, $data = array())
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+
namespace Symfony\Bundle\FrameworkBundle\Tests\Templating\Helper;
13+
14+
use Symfony\Bundle\FrameworkBundle\Templating\Helper\AssetsHelper;
15+
use Symfony\Component\Asset\Package;
16+
use Symfony\Component\Asset\Packages;
17+
use Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy;
18+
19+
class AssetsHelperTest extends \PHPUnit_Framework_TestCase
20+
{
21+
private $helper;
22+
23+
protected function setUp()
24+
{
25+
$fooPackage = new Package(new StaticVersionStrategy('42', '%s?v=%s'));
26+
$barPackage = new Package(new StaticVersionStrategy('22', '%s?%s'));
27+
28+
$packages = new Packages($fooPackage, ['bar' => $barPackage]);
29+
30+
$this->helper = new AssetsHelper($packages);
31+
}
32+
33+
public function testGetUrl()
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+
public function testGetVersion()
40+
{
41+
$this->assertEquals('42', $this->helper->getVersion('/'));
42+
$this->assertEquals('22', $this->helper->getVersion('/', 'bar'));
43+
}
44+
}

Translation/PhpExtractor.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ public function extract($resource, MessageCatalogue $catalog)
6060
$files = $this->extractFiles($resource);
6161
foreach ($files as $file) {
6262
$this->parseTokens(token_get_all(file_get_contents($file)), $catalog);
63+
64+
if (PHP_VERSION_ID >= 70000) {
65+
// PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
66+
gc_mem_caches();
67+
}
6368
}
6469
}
6570

@@ -80,7 +85,7 @@ public function setPrefix($prefix)
8085
*/
8186
protected function normalizeToken($token)
8287
{
83-
if (is_array($token)) {
88+
if (isset($token[1]) && 'b"' !== $token) {
8489
return $token[1];
8590
}
8691

@@ -94,7 +99,7 @@ private function seekToNextRelevantToken(\Iterator $tokenIterator)
9499
{
95100
for (; $tokenIterator->valid(); $tokenIterator->next()) {
96101
$t = $tokenIterator->current();
97-
if (!is_array($t) || ($t[0] !== T_WHITESPACE)) {
102+
if (T_WHITESPACE !== $t[0]) {
98103
break;
99104
}
100105
}
@@ -111,7 +116,7 @@ private function getMessage(\Iterator $tokenIterator)
111116

112117
for (; $tokenIterator->valid(); $tokenIterator->next()) {
113118
$t = $tokenIterator->current();
114-
if (!is_array($t)) {
119+
if (!isset($t[1])) {
115120
break;
116121
}
117122

0 commit comments

Comments
 (0)