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 7605531

Browse filesBrowse files
committed
Merge branch '2.3' into 2.5
* 2.3: [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 Conflicts: src/Symfony/Component/Form/FormConfigBuilder.php
2 parents aeec129 + b8e4b4a commit 7605531
Copy full SHA for 7605531

File tree

Expand file treeCollapse file tree

11 files changed

+112
-29
lines changed
Filter options
Expand file treeCollapse file tree

11 files changed

+112
-29
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/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/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
@@ -1749,7 +1749,7 @@ protected function prepareBaseUrl()
17491749
return $prefix;
17501750
}
17511751

1752-
if ($baseUrl && false !== $prefix = $this->getUrlencodedPrefix($requestUri, dirname($baseUrl))) {
1752+
if ($baseUrl && false !== $prefix = $this->getUrlencodedPrefix($requestUri, dirname($baseUrl).'/')) {
17531753
// directory portion of $baseUrl matches
17541754
return rtrim($prefix, '/');
17551755
}

‎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
/**
@@ -1327,7 +1342,7 @@ public function getBaseUrlData()
13271342
{
13281343
return array(
13291344
array(
1330-
'/foo%20bar',
1345+
'/foo%20bar/',
13311346
array(
13321347
'SCRIPT_FILENAME' => '/home/John Doe/public_html/foo bar/app.php',
13331348
'SCRIPT_NAME' => '/foo bar/app.php',

‎src/Symfony/Component/Yaml/Escaper.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Escaper.php
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ public static function escapeWithDoubleQuotes($value)
7272
*/
7373
public static function requiresSingleQuoting($value)
7474
{
75-
// Determines if the PHP value contains any single characters that would
76-
// cause it to require single quoting in YAML.
77-
if (preg_match('/[ \s \' " \: \{ \} \[ \] , & \* \# \?] | \A[ \- ? | < > = ! % @ ` ]/x', $value)) {
75+
// Determines if a PHP value is entirely composed of a value that would
76+
// require single quoting in YAML.
77+
if (in_array(strtolower($value), array('null', '~', 'true', 'false', 'y', 'n', 'yes', 'no', 'on', 'off'))) {
7878
return true;
7979
}
8080

81-
// Determines if a PHP value is entirely composed of a value that would
82-
// require single quoting in YAML.
83-
return in_array(strtolower($value), array('null', '~', 'true', 'false', 'y', 'n', 'yes', 'no', 'on', 'off'));
81+
// Determines if the PHP value contains any single characters that would
82+
// cause it to require single quoting in YAML.
83+
return preg_match('/[ \s \' " \: \{ \} \[ \] , & \* \# \?] | \A[ \- ? | < > = ! % @ ` ]/x', $value);
8484
}
8585

8686
/**

‎src/Symfony/Component/Yaml/Inline.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Inline.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,13 @@ public static function dump($value, $exceptionOnInvalidType = false, $objectSupp
132132
}
133133

134134
return $repr;
135+
case '' == $value:
136+
return "''";
135137
case Escaper::requiresDoubleQuoting($value):
136138
return Escaper::escapeWithDoubleQuotes($value);
137139
case Escaper::requiresSingleQuoting($value):
138140
case preg_match(self::getTimestampRegex(), $value):
139141
return Escaper::escapeWithSingleQuotes($value);
140-
case '' == $value:
141-
return "''";
142142
default:
143143
return $value;
144144
}

0 commit comments

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