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
This commit is contained in:
Nicolas Grekas 2018-11-08 23:01:02 +01:00
commit 0aa4273b39
7 changed files with 26 additions and 15 deletions

View File

@ -149,6 +149,11 @@
{{- parent() -}}
{%- endblock button_widget %}
{% block submit_widget -%}
{%- set attr = attr|merge({class: (attr.class|default('btn-primary'))|trim}) -%}
{{- parent() -}}
{%- endblock submit_widget %}
{% block checkbox_widget -%}
{%- set parent_label_class = parent_label_class|default(label_attr.class|default('')) -%}
{%- if 'checkbox-custom' in parent_label_class -%}

View File

@ -101,8 +101,8 @@ final class Dotenv
*/
public function populate(array $values, bool $overrideExistingVars = false): void
{
$loadedVars = array_flip(explode(',', getenv('SYMFONY_DOTENV_VARS')));
unset($loadedVars['']);
$updateLoadedVars = false;
$loadedVars = array_flip(explode(',', $_SERVER['SYMFONY_DOTENV_VARS'] ?? $_ENV['SYMFONY_DOTENV_VARS'] ?? '')));
foreach ($values as $name => $value) {
$notHttpName = 0 !== strpos($name, 'HTTP_');
@ -117,14 +117,15 @@ final class Dotenv
$_SERVER[$name] = $value;
}
$loadedVars[$name] = true;
if (!isset($loadedVars[$name])) {
$loadedVars[$name] = $updateLoadedVars = true;
}
}
if ($loadedVars) {
if ($updateLoadedVars) {
unset($loadedVars['']);
$loadedVars = implode(',', array_keys($loadedVars));
putenv("SYMFONY_DOTENV_VARS=$loadedVars");
$_ENV['SYMFONY_DOTENV_VARS'] = $loadedVars;
$_SERVER['SYMFONY_DOTENV_VARS'] = $loadedVars;
putenv('SYMFONY_DOTENV_VARS='.$_ENV['SYMFONY_DOTENV_VARS'] = $_SERVER['SYMFONY_DOTENV_VARS'] = $loadedVars);
}
}

View File

@ -373,7 +373,7 @@ class DotenvTest extends TestCase
public function testOverridingEnvVarsWithNamesMemorizedInSpecialVar()
{
putenv('SYMFONY_DOTENV_VARS=FOO,BAR,BAZ');
putenv('SYMFONY_DOTENV_VARS='.$_SERVER['SYMFONY_DOTENV_VARS'] = 'FOO,BAR,BAZ');
putenv('FOO=foo');
putenv('BAR=bar');

View File

@ -174,7 +174,7 @@ class ParameterBag implements \IteratorAggregate, \Countable
* Returns the parameter value converted to boolean.
*
* @param string $key The parameter key
* @param mixed $default The default value if the parameter key does not exist
* @param bool $default The default value if the parameter key does not exist
*
* @return bool The filtered value
*/

View File

@ -336,8 +336,9 @@ class Response
// headers
foreach ($this->headers->allPreserveCaseWithoutCookies() as $name => $values) {
$replace = 0 === strcasecmp($name, 'Content-Type');
foreach ($values as $value) {
header($name.': '.$value, false, $this->statusCode);
header($name.': '.$value, $replace, $this->statusCode);
}
}

View File

@ -433,8 +433,10 @@ abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerIn
// Don't run set for a parameter passed to the constructor
$params[] = $parameterData;
unset($data[$key]);
} elseif (null !== $param = $context[self::DEFAULT_CONSTRUCTOR_ARGUMENTS][$class][$key] ?? $this->defaultContext[self::DEFAULT_CONSTRUCTOR_ARGUMENTS][$class][$key] ?? null) {
$params[] = $param;
} elseif (array_key_exists($key, $context[static::DEFAULT_CONSTRUCTOR_ARGUMENTS][$class] ?? array())) {
$params[] = $context[static::DEFAULT_CONSTRUCTOR_ARGUMENTS][$class][$key];
} elseif (array_key_exists($key, $this->defaultContext[self::DEFAULT_CONSTRUCTOR_ARGUMENTS][$class] ?? array())) {
$params[] = $this->defaultContext[self::DEFAULT_CONSTRUCTOR_ARGUMENTS][$class][$key];
} elseif ($constructorParameter->isDefaultValueAvailable()) {
$params[] = $constructorParameter->getDefaultValue();
} else {

View File

@ -254,11 +254,11 @@ class ObjectNormalizerTest extends TestCase
$result = $normalizer->denormalize($data, DummyValueObject::class, 'json', array(
'default_constructor_arguments' => array(
DummyValueObject::class => array('foo' => '', 'bar' => ''),
DummyValueObject::class => array('foo' => '', 'bar' => '', 'baz' => null),
),
));
$this->assertEquals(new DummyValueObject(10, ''), $result);
$this->assertEquals(new DummyValueObject(10, '', null), $result);
}
public function testGroupsNormalize()
@ -1268,11 +1268,13 @@ class DummyValueObject
{
private $foo;
private $bar;
private $baz;
public function __construct($foo, $bar)
public function __construct($foo, $bar, $baz)
{
$this->foo = $foo;
$this->bar = $bar;
$this->baz = $baz;
}
}