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

Appearance settings

Commit db80498

Browse filesBrowse files
committed
Merge branch '2.7'
* 2.7: Minor plural/singular change print error message if server couldn't be started [HttpFoundation] [Request] fix baseUrl parsing to fix wrong path_info [Twig][Bridge][TranslationDefaultDomain] add support of named arguments. [Form] Improved exception message if the data class is not found Fixes ArgvInput's argument getter with empty tokens execute cheaper checks before more expensive ones [DependencyInjection] Fix missing ExpressionLanguageProviders on extension bild [FrameworkBundle] FormDataCollector should be loaded only if form config is enabled
2 parents 620744f + ba9392c commit db80498
Copy full SHA for db80498

File tree

Expand file treeCollapse file tree

17 files changed

+209
-41
lines changed
Filter options
Expand file treeCollapse file tree

17 files changed

+209
-41
lines changed

‎src/Symfony/Bridge/Twig/NodeVisitor/TranslationDefaultDomainNodeVisitor.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/NodeVisitor/TranslationDefaultDomainNodeVisitor.php
+25-5Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,20 @@ public function enterNode(\Twig_NodeInterface $node, \Twig_Environment $env)
6262
}
6363

6464
if ($node instanceof \Twig_Node_Expression_Filter && in_array($node->getNode('filter')->getAttribute('value'), array('trans', 'transchoice'))) {
65-
$ind = 'trans' === $node->getNode('filter')->getAttribute('value') ? 1 : 2;
6665
$arguments = $node->getNode('arguments');
67-
if (!$arguments->hasNode($ind)) {
68-
if (!$arguments->hasNode($ind - 1)) {
69-
$arguments->setNode($ind - 1, new \Twig_Node_Expression_Array(array(), $node->getLine()));
66+
$ind = 'trans' === $node->getNode('filter')->getAttribute('value') ? 1 : 2;
67+
if ($this->isNamedArguments($arguments)) {
68+
if (!$arguments->hasNode('domain') && !$arguments->hasNode($ind)) {
69+
$arguments->setNode('domain', $this->scope->get('domain'));
7070
}
71+
} else {
72+
if (!$arguments->hasNode($ind)) {
73+
if (!$arguments->hasNode($ind - 1)) {
74+
$arguments->setNode($ind - 1, new \Twig_Node_Expression_Array(array(), $node->getLine()));
75+
}
7176

72-
$arguments->setNode($ind, $this->scope->get('domain'));
77+
$arguments->setNode($ind, $this->scope->get('domain'));
78+
}
7379
}
7480
} elseif ($node instanceof TransNode) {
7581
if (null === $node->getNode('domain')) {
@@ -103,4 +109,18 @@ public function getPriority()
103109
{
104110
return -10;
105111
}
112+
113+
/**
114+
* @return bool
115+
*/
116+
private function isNamedArguments($arguments)
117+
{
118+
foreach ($arguments as $name => $node) {
119+
if (!is_int($name)) {
120+
return true;
121+
}
122+
}
123+
124+
return false;
125+
}
106126
}

‎src/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,40 @@ public function testDefaultTranslationDomain()
147147
$this->assertEquals('foo (foo)foo (custom)foo (foo)foo (custom)foo (foo)foo (custom)', trim($template->render(array())));
148148
}
149149

150+
public function testDefaultTranslationDomainWithNamedArguments()
151+
{
152+
$templates = array(
153+
'index' => '
154+
{%- trans_default_domain "foo" %}
155+
156+
{%- block content %}
157+
{{- "foo"|trans(arguments = {}, domain = "custom") }}
158+
{{- "foo"|transchoice(count = 1) }}
159+
{{- "foo"|transchoice(count = 1, arguments = {}, domain = "custom") }}
160+
{{- "foo"|trans({}, domain = "custom") }}
161+
{{- "foo"|trans({}, "custom", locale = "fr") }}
162+
{{- "foo"|transchoice(1, arguments = {}, domain = "custom") }}
163+
{{- "foo"|transchoice(1, {}, "custom", locale = "fr") }}
164+
{% endblock %}
165+
',
166+
167+
'base' => '
168+
{%- block content "" %}
169+
',
170+
);
171+
172+
$translator = new Translator('en', new MessageSelector());
173+
$translator->addLoader('array', new ArrayLoader());
174+
$translator->addResource('array', array('foo' => 'foo (messages)'), 'en');
175+
$translator->addResource('array', array('foo' => 'foo (custom)'), 'en', 'custom');
176+
$translator->addResource('array', array('foo' => 'foo (foo)'), 'en', 'foo');
177+
$translator->addResource('array', array('foo' => 'foo (fr)'), 'fr', 'custom');
178+
179+
$template = $this->getTemplate($templates, $translator);
180+
181+
$this->assertEquals('foo (custom)foo (foo)foo (custom)foo (custom)foo (fr)foo (custom)foo (fr)', trim($template->render(array())));
182+
}
183+
150184
protected function getTemplate($template, $translator = null)
151185
{
152186
if (null === $translator) {

‎src/Symfony/Bridge/Twig/Tests/NodeVisitor/TranslationDefaultDomainNodeVisitorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Tests/NodeVisitor/TranslationDefaultDomainNodeVisitorTest.php
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ public function getDefaultDomainAssignmentTestData()
7777
array(TwigNodeProvider::getTransFilter(self::$message)),
7878
array(TwigNodeProvider::getTransChoiceFilter(self::$message)),
7979
array(TwigNodeProvider::getTransTag(self::$message)),
80+
// with named arguments
81+
array(TwigNodeProvider::getTransFilter(self::$message, null, array(
82+
'arguments' => new \Twig_Node_Expression_Array(array(), 0),
83+
))),
84+
array(TwigNodeProvider::getTransChoiceFilter(self::$message), null, array(
85+
'arguments' => new \Twig_Node_Expression_Array(array(), 0),
86+
)),
8087
);
8188
}
8289
}

‎src/Symfony/Bridge/Twig/Tests/NodeVisitor/TwigNodeProvider.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Tests/NodeVisitor/TwigNodeProvider.php
+15-11Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ public static function getModule($content)
2929
);
3030
}
3131

32-
public static function getTransFilter($message, $domain = null)
32+
public static function getTransFilter($message, $domain = null, $arguments = null)
3333
{
34-
$arguments = $domain ? array(
35-
new \Twig_Node_Expression_Array(array(), 0),
36-
new \Twig_Node_Expression_Constant($domain, 0),
37-
) : array();
34+
if (!$arguments) {
35+
$arguments = $domain ? array(
36+
new \Twig_Node_Expression_Array(array(), 0),
37+
new \Twig_Node_Expression_Constant($domain, 0),
38+
) : array();
39+
}
3840

3941
return new \Twig_Node_Expression_Filter(
4042
new \Twig_Node_Expression_Constant($message, 0),
@@ -44,13 +46,15 @@ public static function getTransFilter($message, $domain = null)
4446
);
4547
}
4648

47-
public static function getTransChoiceFilter($message, $domain = null)
49+
public static function getTransChoiceFilter($message, $domain = null, $arguments = null)
4850
{
49-
$arguments = $domain ? array(
50-
new \Twig_Node_Expression_Constant(0, 0),
51-
new \Twig_Node_Expression_Array(array(), 0),
52-
new \Twig_Node_Expression_Constant($domain, 0),
53-
) : array();
51+
if (!$arguments) {
52+
$arguments = $domain ? array(
53+
new \Twig_Node_Expression_Constant(0, 0),
54+
new \Twig_Node_Expression_Array(array(), 0),
55+
new \Twig_Node_Expression_Constant($domain, 0),
56+
) : array();
57+
}
5458

5559
return new \Twig_Node_Expression_Filter(
5660
new \Twig_Node_Expression_Constant($message, 0),

‎src/Symfony/Bundle/FrameworkBundle/Command/ServerStartCommand.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Command/ServerStartCommand.php
+34-2Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,19 @@ protected function execute(InputInterface $input, OutputInterface $output)
9191
}
9292

9393
$env = $this->getContainer()->getParameter('kernel.environment');
94+
$address = $input->getArgument('address');
95+
96+
if (false === strpos($address, ':')) {
97+
$output->writeln('The address has to be of the form <comment>bind-address:port</comment>.');
98+
99+
return 1;
100+
}
101+
102+
if ($this->isOtherServerProcessRunning($address)) {
103+
$output->writeln(sprintf('<error>A process is already listening on http://%s.</error>', $address));
104+
105+
return 1;
106+
}
94107

95108
if ('prod' === $env) {
96109
$output->writeln('<error>Running PHP built-in server in production environment is NOT recommended!</error>');
@@ -104,8 +117,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
104117
return 1;
105118
}
106119

107-
$address = $input->getArgument('address');
108-
109120
if ($pid > 0) {
110121
$output->writeln(sprintf('<info>Web server listening on http://%s</info>', $address));
111122

@@ -144,6 +155,27 @@ protected function execute(InputInterface $input, OutputInterface $output)
144155
}
145156
}
146157

158+
private function isOtherServerProcessRunning($address)
159+
{
160+
$lockFile = $this->getLockFile($address);
161+
162+
if (file_exists($lockFile)) {
163+
return true;
164+
}
165+
166+
list($hostname, $port) = explode(':', $address);
167+
168+
$fp = @fsockopen($hostname, $port, $errno, $errstr, 5);
169+
170+
if (false !== $fp) {
171+
fclose($fp);
172+
173+
return true;
174+
}
175+
176+
return false;
177+
}
178+
147179
/**
148180
* Creates a process to start PHP's built-in web server.
149181
*

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/collectors.xml
-9Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
<parameter key="data_collector.time.class">Symfony\Component\HttpKernel\DataCollector\TimeDataCollector</parameter>
1414
<parameter key="data_collector.memory.class">Symfony\Component\HttpKernel\DataCollector\MemoryDataCollector</parameter>
1515
<parameter key="data_collector.router.class">Symfony\Bundle\FrameworkBundle\DataCollector\RouterDataCollector</parameter>
16-
<parameter key="data_collector.form.class">Symfony\Component\Form\Extension\DataCollector\FormDataCollector</parameter>
17-
<parameter key="data_collector.form.extractor.class">Symfony\Component\Form\Extension\DataCollector\FormDataExtractor</parameter>
1816
</parameters>
1917

2018
<services>
@@ -61,12 +59,5 @@
6159
<tag name="kernel.event_listener" event="kernel.controller" method="onKernelController"/>
6260
<tag name="data_collector" template="@WebProfiler/Collector/router.html.twig" id="router" priority="255" />
6361
</service>
64-
65-
<service id="data_collector.form.extractor" class="%data_collector.form.extractor.class%" />
66-
67-
<service id="data_collector.form" class="%data_collector.form.class%">
68-
<tag name="data_collector" template="@WebProfiler/Collector/form.html.twig" id="form" priority="255" />
69-
<argument type="service" id="data_collector.form.extractor" />
70-
</service>
7162
</services>
7263
</container>

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/form_debug.xml
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
<parameters>
88
<parameter key="form.resolved_type_factory.data_collector_proxy.class">Symfony\Component\Form\Extension\DataCollector\Proxy\ResolvedTypeFactoryDataCollectorProxy</parameter>
99
<parameter key="form.type_extension.form.data_collector.class">Symfony\Component\Form\Extension\DataCollector\Type\DataCollectorTypeExtension</parameter>
10+
<parameter key="data_collector.form.class">Symfony\Component\Form\Extension\DataCollector\FormDataCollector</parameter>
11+
<parameter key="data_collector.form.extractor.class">Symfony\Component\Form\Extension\DataCollector\FormDataExtractor</parameter>
1012
</parameters>
1113

1214
<services>
@@ -22,5 +24,13 @@
2224
<tag name="form.type_extension" alias="form" />
2325
<argument type="service" id="data_collector.form" />
2426
</service>
27+
28+
<!-- DataCollector -->
29+
<service id="data_collector.form.extractor" class="%data_collector.form.extractor.class%" />
30+
31+
<service id="data_collector.form" class="%data_collector.form.class%">
32+
<tag name="data_collector" template="@WebProfiler/Collector/form.html.twig" id="form" priority="255" />
33+
<argument type="service" id="data_collector.form.extractor" />
34+
</service>
2535
</services>
2636
</container>

‎src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
tbody.appendChild(rows);
145145
146146
if (infoSpan) {
147-
var text = requestStack.length + ' calls';
147+
var text = requestStack.length + ' call' + (requestStack.length > 1 ? 's' : '');
148148
infoSpan.textContent = text;
149149
}
150150
} else {

‎src/Symfony/Component/Console/Input/ArgvInput.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Input/ArgvInput.php
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,11 @@ public function hasParameterOption($values)
309309
public function getParameterOption($values, $default = false)
310310
{
311311
$values = (array) $values;
312-
313312
$tokens = $this->tokens;
314-
while ($token = array_shift($tokens)) {
313+
314+
while (0 < count($tokens)) {
315+
$token = array_shift($tokens);
316+
315317
foreach ($values as $value) {
316318
if ($token === $value || 0 === strpos($token, $value.'=')) {
317319
if (false !== $pos = strpos($token, '=')) {

‎src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ public function provideGetParameterOptionValues()
304304
array(array('app/console', 'foo:bar', '-e', 'dev'), array('-e', '--env'), 'dev'),
305305
array(array('app/console', 'foo:bar', '--env=dev'), array('-e', '--env'), 'dev'),
306306
array(array('app/console', 'foo:bar', '--env=dev', '--en=1'), array('--en'), '1'),
307+
array(array('app/console', 'foo:bar', '--env=dev', '', '--en=1'), array('--en'), '1'),
307308
);
308309
}
309310

‎src/Symfony/Component/DependencyInjection/Compiler/MergeExtensionConfigurationPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/MergeExtensionConfigurationPass.php
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public function process(ContainerBuilder $container)
2929
$parameters = $container->getParameterBag()->all();
3030
$definitions = $container->getDefinitions();
3131
$aliases = $container->getAliases();
32+
$exprLangProviders = $container->getExpressionLanguageProviders();
3233

3334
foreach ($container->getExtensions() as $extension) {
3435
if ($extension instanceof PrependExtensionInterface) {
@@ -47,6 +48,10 @@ public function process(ContainerBuilder $container)
4748
$tmpContainer->setResourceTracking($container->isTrackingResources());
4849
$tmpContainer->addObjectResource($extension);
4950

51+
foreach ($exprLangProviders as $provider) {
52+
$tmpContainer->addExpressionLanguageProvider($provider);
53+
}
54+
5055
$extension->load($config, $tmpContainer);
5156

5257
$container->merge($tmpContainer);
+47Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
4+
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
5+
6+
use Symfony\Component\DependencyInjection\Compiler\MergeExtensionConfigurationPass;
7+
use Symfony\Component\DependencyInjection\ContainerBuilder;
8+
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
9+
10+
class MergeExtensionConfigurationPassTest extends \PHPUnit_Framework_TestCase
11+
{
12+
public function testExpressionLanguageProviderForwarding()
13+
{
14+
if (true !== class_exists('Symfony\\Component\\ExpressionLanguage\\ExpressionLanguage')) {
15+
$this->markTestSkipped('The ExpressionLanguage component isn\'t available!');
16+
}
17+
18+
$tmpProviders = array();
19+
20+
$extension = $this->getMock('Symfony\\Component\\DependencyInjection\\Extension\\ExtensionInterface');
21+
$extension->expects($this->any())
22+
->method('getXsdValidationBasePath')
23+
->will($this->returnValue(false));
24+
$extension->expects($this->any())
25+
->method('getNamespace')
26+
->will($this->returnValue('http://example.org/schema/dic/foo'));
27+
$extension->expects($this->any())
28+
->method('getAlias')
29+
->will($this->returnValue('foo'));
30+
$extension->expects($this->once())
31+
->method('load')
32+
->will($this->returnCallback(function (array $config, ContainerBuilder $container) use (&$tmpProviders) {
33+
$tmpProviders = $container->getExpressionLanguageProviders();
34+
}));
35+
36+
$provider = $this->getMock('Symfony\\Component\\ExpressionLanguage\\ExpressionFunctionProviderInterface');
37+
$container = new ContainerBuilder(new ParameterBag());
38+
$container->registerExtension($extension);
39+
$container->prependExtensionConfig('foo', array('bar' => true ));
40+
$container->addExpressionLanguageProvider($provider);
41+
42+
$pass = new MergeExtensionConfigurationPass();
43+
$pass->process($container);
44+
45+
$this->assertEquals(array($provider), $tmpProviders);
46+
}
47+
}

‎src/Symfony/Component/Form/FormConfigBuilder.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/FormConfigBuilder.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public function __construct($name, $dataClass, EventDispatcherInterface $dispatc
193193
self::validateName($name);
194194

195195
if (null !== $dataClass && !class_exists($dataClass) && !interface_exists($dataClass)) {
196-
throw new InvalidArgumentException(sprintf('The data class "%s" is not a valid class.', $dataClass));
196+
throw new InvalidArgumentException(sprintf('Class "%s" not found. Is the "data_class" form option set correctly?', $dataClass));
197197
}
198198

199199
$this->name = (string) $name;

‎src/Symfony/Component/HttpFoundation/Request.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Request.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1815,7 +1815,7 @@ protected function prepareBaseUrl()
18151815
return $prefix;
18161816
}
18171817

1818-
if ($baseUrl && false !== $prefix = $this->getUrlencodedPrefix($requestUri, dirname($baseUrl))) {
1818+
if ($baseUrl && false !== $prefix = $this->getUrlencodedPrefix($requestUri, dirname($baseUrl).'/')) {
18191819
// directory portion of $baseUrl matches
18201820
return rtrim($prefix, '/');
18211821
}

‎src/Symfony/Component/HttpFoundation/Tests/RequestTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
+16-1Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,21 @@ public function testCreate()
223223
$request = Request::create('http://test.com/?foo');
224224
$this->assertEquals('/?foo', $request->getRequestUri());
225225
$this->assertEquals(array('foo' => ''), $request->query->all());
226+
227+
## assume rewrite rule: (.*) --> app/app.php ; app/ is a symlink to a symfony web/ directory
228+
$request = Request::create('http://test.com/apparthotel-1234', 'GET', array(), array(), array(),
229+
array(
230+
'DOCUMENT_ROOT' => '/var/www/www.test.com',
231+
'SCRIPT_FILENAME' => '/var/www/www.test.com/app/app.php',
232+
'SCRIPT_NAME' => '/app/app.php',
233+
'PHP_SELF' => '/app/app.php/apparthotel-1234',
234+
));
235+
$this->assertEquals('http://test.com/apparthotel-1234', $request->getUri());
236+
$this->assertEquals('/apparthotel-1234', $request->getPathInfo());
237+
$this->assertEquals('', $request->getQueryString());
238+
$this->assertEquals(80, $request->getPort());
239+
$this->assertEquals('test.com', $request->getHttpHost());
240+
$this->assertFalse($request->isSecure());
226241
}
227242

228243
/**
@@ -1347,7 +1362,7 @@ public function getBaseUrlData()
13471362
{
13481363
return array(
13491364
array(
1350-
'/foo%20bar',
1365+
'/foo%20bar/',
13511366
array(
13521367
'SCRIPT_FILENAME' => '/home/John Doe/public_html/foo bar/app.php',
13531368
'SCRIPT_NAME' => '/foo bar/app.php',

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.