10000 Merge branch '2.0' into 2.1 · sensi/symfony@82a6694 · GitHub
[go: up one dir, main page]

Skip to content

Commit 82a6694

Browse files
committed
Merge branch '2.0' into 2.1
* 2.0: [Form] Fixed creation of multiple money fields with different currencies Fixed IPv6 Check in RequestMatcher fixed DomCrwaler/Form to handle <button> when submitted Conflicts: tests/Symfony/Tests/Component/DomCrawler/FormTest.php tests/Symfony/Tests/Component/Form/Extension/Core/Type/MoneyTypeTest.php
2 parents 1c7f5d4 + 1fddce4 commit 82a6694

File tree

6 files changed

+35
-12
lines changed

6 files changed

+35
-12
lines changed

src/Symfony/Component/DomCrawler/Field/InputFormField.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ class InputFormField extends FormField
3030
*/
3131
protected function initialize()
3232
{
33-
if ('input' != $this->node->nodeName) {
34-
throw new \LogicException(sprintf('An InputFormField can only be created from an input tag (%s given).', $this->node->nodeName));
33+
if ('input' != $this->node->nodeName && 'button' != $this->node->nodeName) {
34+
throw new \LogicException(sprintf('An InputFormField can only be created from an input or button tag (%s given).', $this->node->nodeName));
3535
}
3636

3737
if ('checkbox' == $this->node->getAttribute('type')) {

src/Symfony/Component/DomCrawler/Form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ private function initialize()
358358
$root->appendChild($button);
359359
$xpath = new \DOMXPath($document);
360360

361-
foreach ($xpath->query('descendant::input | descendant::textarea | descendant::select', $root) 10000 as $node) {
361+
foreach ($xpath->query('descendant::input | descendant::button | descendant::textarea | descendant::select', $root) as $node) {
362362
if (!$node->hasAttribute('name')) {
363363
continue;
364364
}

src/Symfony/Component/DomCrawler/Tests/FormTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ public function provideInitializeValues()
137137
'<input type="submit" name="bar" value="bar" />',
138138
array('bar' => array('InputFormField', 'bar')),
139139
),
140+
array(
141+
'appends the submitted button value for Button element',
142+
'<button type="submit" name="bar" value="bar">Bar</button>',
143+
array('bar' => array('InputFormField', 'bar')),
144+
),
140145
array(
141146
'appends the submitted button value but not other submit buttons',
142147
'<input type="submit" name="bar" value="bar" />
@@ -668,6 +673,8 @@ protected function createForm($form, $method = null, $currentUri = null)
668673
$dom->loadHTML('<html>'.$form.'</html>');
669674

670675
$nodes = $dom->getElementsByTagName('input');
676+
$xPath = new \DOMXPath($dom);
677+
$nodes = $xPath->query('//input | //button');
671678

672679
if (null === $currentUri) {
673680
$currentUri = 'http://example.com/';

src/Symfony/Component/Form/Extension/Core/Type/MoneyType.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,14 @@ private static function getPattern($currency)
8787
return '{{ widget }}';
8888
}
8989

90-
if (!isset(self::$patterns[\Locale::getDefault()])) {
91-
self::$patterns[\Locale::getDefault()] = array();
90+
$locale = \Locale::getDefault();
91+
92+
if (!isset(self::$patterns[$locale])) {
93+
self::$patterns[$locale] = array();
9294
}
9395

94-
if (!isset(self::$patterns[\Locale::getDefault()][$currency])) {
95-
$format = new \NumberFormatter(\Locale::getDefault(), \NumberFormatter::CURRENCY);
96+
if (!isset(self::$patterns[$locale][$currency])) {
97+
$format = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
9698
$pattern = $format->formatCurrency('123', $currency);
9799

98100
// the spacings between currency symbol and number are ignored, because
@@ -104,14 +106,14 @@ private static function getPattern($currency)
104106
preg_match('/^([^\s\xc2\xa0]*)[\s\xc2\xa0]*123(?:[,.]0+)?[\s\xc2\xa0]*([^\s\xc2\xa0]*)$/u', $pattern, $matches);
105107

106108
if (!empty($matches[1])) {
107-
self::$patterns[\Locale::getDefault()] = $matches[1].' {{ widget }}';
109+
self::$patterns[$locale][$currency] = $matches[1].' {{ widget }}';
108110
} elseif (!empty($matches[2])) {
109-
self::$patterns[\Locale::getDefault()] = '{{ widget }} '.$matches[2];
111+
self::$patterns[$locale][$currency] = '{{ widget }} '.$matches[2];
110112
} else {
111-
self::$patterns[\Locale::getDefault()] = '{{ widget }}';
113+
self::$patterns[$locale][$currency] = '{{ widget }}';
112114
}
113115
}
114116

115-
return self::$patterns[\Locale::getDefault()];
117+
return self::$patterns[$locale][$currency];
116118
}
117119
}

src/Symfony/Component/Form/Tests/Extension/Core/Type/MoneyTypeTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,18 @@ public function testMoneyPatternWorksForYen()
3131
$view = $form->createView();
3232
$this->assertTrue((Boolean) strstr($view->vars['money_pattern'], '¥'));
3333
}
34+
35+
// https://github.com/symfony/symfony/issues/5458
36+
public function testPassDifferentPatternsForDifferentCurrencies()
37+
{
38+
\Locale::setDefault('de_DE');
39+
40+
$form1 = $this->factory->create('money', null, array('currency' => 'GBP'));
41+
$form2 = $this->factory->create('money', null, array('currency' => 'EUR'));
42+
$view1 = $form1->createView();
43+
$view2 = $form2->createView();
44+
45+
$this->assertSame('{{ widget }} £', $view1->get('money_pattern'));
46+
$this->assertSame('{{ widget }} €', $view2->get('money_pattern'));
47+
}
3448
}

src/Symfony/Component/HttpFoundation/RequestMatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ protected function checkIp4($requestIp, $ip)
198198
*/
199199
protected function checkIp6($requestIp, $ip)
200200
{
201-
if (!defined('AF_INET6')) {
201+
if (!((extension_loaded('sockets') && defined('AF_INET6')) || @inet_pton('::1'))) {
202202
throw new \RuntimeException('Unable to check Ipv6. Check that PHP was not compiled with option "disable-ipv6".');
203203
}
204204

0 commit comments

Comments
 (0)
0