Skip to content

Commit 0aa4273

Browse files
Merge branch '4.1'
* 4.1: Change button_widget class to btn-primary [Serializer] Allow null values when denormalizing with constructor missing data [Dotenv] dont use getenv() to read SYMFONY_DOTENV_VARS [HttpFoundation] Fixed PHP doc of ParameterBag::getBoolean [HttpFoundation] replace any preexisting Content-Type headers
2 parents 6ba1803 + f45252a commit 0aa4273

File tree

7 files changed

+26
-15
lines changed

7 files changed

+26
-15
lines changed

src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@
149149
{{- parent() -}}
150150
{%- endblock button_widget %}
151151

152+
{% block submit_widget -%}
153+
{%- set attr = attr|merge({class: (attr.class|default('btn-primary'))|trim}) -%}
154+
{{- parent() -}}
155+
{%- endblock submit_widget %}
156+
152157
{% block checkbox_widget -%}
153158
{%- set parent_label_class = parent_label_class|default(label_attr.class|default('')) -%}
154159
{%- if 'checkbox-custom' in parent_label_class -%}

src/Symfony/Component/Dotenv/Dotenv.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ public function overload(string $path, string ...$extraPaths): void
101101
*/
102102
public function populate(array $values, bool $overrideExistingVars = false): void
103103
{
104-
$loadedVars = array_flip(explode(',', getenv('SYMFONY_DOTENV_VARS')));
105-
unset($loadedVars['']);
104+
$updateLoadedVars = false;
105+
$loadedVars = array_flip(explode(',', $_SERVER['SYMFONY_DOTENV_VARS'] ?? $_ENV['SYMFONY_DOTENV_VARS'] ?? '')));
106106

107107
foreach ($values as $name => $value) {
108108
$notHttpName = 0 !== strpos($name, 'HTTP_');
@@ -117,14 +117,15 @@ public function populate(array $values, bool $overrideExistingVars = false): voi
117117
$_SERVER[$name] = $value;
118118
}
119119

120-
$loadedVars[$name] = true;
120+
if (!isset($loadedVars[$name])) {
121+
$loadedVars[$name] = $updateLoadedVars = true;
122+
}
121123
}
122124

123-
if ($loadedVars) {
125+
if ($updateLoadedVars) {
126+
unset($loadedVars['']);
124127
$loadedVars = implode(',', array_keys($loadedVars));
125-
putenv("SYMFONY_DOTENV_VARS=$loadedVars");
126-
$_ENV['SYMFONY_DOTENV_VARS'] = $loadedVars;
127-
$_SERVER['SYMFONY_DOTENV_VARS'] = $loadedVars;
128+
putenv('SYMFONY_DOTENV_VARS='.$_ENV['SYMFONY_DOTENV_VARS'] = $_SERVER['SYMFONY_DOTENV_VARS'] = $loadedVars);
128129
}
129130
}
130131

src/Symfony/Component/Dotenv/Tests/DotenvTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ public function testMemorizingLoadedVarsNamesInSpecialVar()
373373

374374
public function testOverridingEnvVarsWithNamesMemorizedInSpecialVar()
375375
{
376-
putenv('SYMFONY_DOTENV_VARS=FOO,BAR,BAZ');
376+
putenv('SYMFONY_DOTENV_VARS='.$_SERVER['SYMFONY_DOTENV_VARS'] = 'FOO,BAR,BAZ');
377377

378378
putenv('FOO=foo');
379379
putenv('BAR=bar');

src/Symfony/Component/HttpFoundation/ParameterBag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public function getInt($key, $default = 0)
174174
* Returns the parameter value converted to boolean.
175175
*
176176
* @param string $key The parameter key
177-
* @param mixed $default The default value if the parameter key does not exist
177+
* @param bool $default The default value if the parameter key does not exist
178178
*
179179
* @return bool The filtered value
180180
*/

src/Symfony/Component/HttpFoundation/Response.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,9 @@ public function sendHeaders()
336336

337337
// headers
338338
foreach ($this->headers->allPreserveCaseWithoutCookies() as $name => $values) {
339+
$replace = 0 === strcasecmp($name, 'Content-Type');
339340
foreach ($values as $value) {
340-
header($name.': '.$value, false, $this->statusCode);
341+
header($name.': '.$value, $replace, $this->statusCode);
341342
}
342343
}
343344

src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,10 @@ protected function instantiateObject(array &$data, $class, array &$context, \Ref
433433
// Don't run set for a parameter passed to the constructor
434434
$params[] = $parameterData;
435435
unset($data[$key]);
436-
} elseif (null !== $param = $context[self::DEFAULT_CONSTRUCTOR_ARGUMENTS][$class][$key] ?? $this->defaultContext[self::DEFAULT_CONSTRUCTOR_ARGUMENTS][$class][$key] ?? null) {
437-
$params[] = $param;
436+
} elseif (array_key_exists($key, $context[static::DEFAULT_CONSTRUCTOR_ARGUMENTS][$class] ?? array())) {
437+
$params[] = $context[static::DEFAULT_CONSTRUCTOR_ARGUMENTS][$class][$key];
438+
} elseif (array_key_exists($key, $this->defaultContext[self::DEFAULT_CONSTRUCTOR_ARGUMENTS][$class] ?? array())) {
439+
$params[] = $this->defaultContext[self::DEFAULT_CONSTRUCTOR_ARGUMENTS][$class][$key];
438440
} elseif ($constructorParameter->isDefaultValueAvailable()) {
439441
$params[] = $constructorParameter->getDefaultValue();
440442
} else {

src/Symfony/Component/Serializer/Tests/Normalizer/ObjectNormalizerTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,11 @@ public function testFillWithEmptyDataWhenMissingData()
254254

255255
$result = $normalizer->denormalize($data, DummyValueObject::class, 'json', array(
256256
'default_constructor_arguments' => array(
257-
DummyValueObject::class => array('foo' => '', 'bar' => ''),
257+
DummyValueObject::class => array('foo' => '', 'bar' => '', 'baz' => null),
258258
),
259259
));
260260

261-
$this->assertEquals(new DummyValueObject(10, ''), $result);
261+
$this->assertEquals(new DummyValueObject(10, '', null), $result);
262262
}
263263

264264
public function testGroupsNormalize()
@@ -1268,11 +1268,13 @@ class DummyValueObject
12681268
{
12691269
private $foo;
12701270
private $bar;
1271+
private $baz;
12711272

1272-
public function __construct($foo, $bar)
1273+
public function __construct($foo, $bar, $baz)
12731274
{
12741275
$this->foo = $foo;
12751276
$this->bar = $bar;
1277+
$this->baz = $baz;
12761278
}
12771279
}
12781280

0 commit comments

Comments
 (0)