8000 Merge branch '2.7' into 2.8 · symfony/symfony@dee62e7 · GitHub
[go: up one dir, main page]

Skip to content

Commit dee62e7

Browse files
Merge branch '2.7' into 2.8
* 2.7: [DoctrineBridge] Fix required guess of boolean fields [DI] don't use array_map to resolve services Remove dead code in the PropertyPath constructor [Process] Inherit env vars by default in PhpProcess Changed one console output style to avoid visual issues [VarDumper] Fix return type and anonymous classes dumping [HttpFoundation] Fixes /0 subnet handling in IpUtils [Form] Simplify DateTimeToStringTransformer Avoid unneeded catch and re-throw of the same exception. [HttpKernel] Remove a duplicate test for the EsiFragmentRenderer Conflicts: src/Symfony/Component/BrowserKit/composer.json src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php
2 parents b8e7bb5 + 86b99ab commit dee62e7

File tree

18 files changed

+108
-82
lines changed
  • VarDumper
  • 18 files changed

    +108
    -82
    lines changed

    src/Symfony/Bridge/Doctrine/Form/DoctrineOrmTypeGuesser.php

    Lines changed: 18 additions & 17 deletions
    Original file line numberDiff line numberDiff line change
    @@ -12,8 +12,9 @@
    1212
    namespace Symfony\Bridge\Doctrine\Form;
    1313

    1414
    use Doctrine\Common\Persistence\ManagerRegistry;
    15-
    use Doctrine\ORM\Mapping\ClassMetadataInfo;
    1615
    use Doctrine\Common\Persistence\Mapping\MappingException;
    16+
    use Doctrine\DBAL\Types\Type;
    17+
    use Doctrine\ORM\Mapping\ClassMetadataInfo;
    1718
    use Doctrine\ORM\Mapping\MappingException as LegacyMappingException;
    1819
    use Symfony\Component\Form\FormTypeGuesserInterface;
    1920
    use Symfony\Component\Form\Guess\Guess;
    @@ -51,28 +52,28 @@ public function guessType($class, $property)
    5152
    }
    5253

    5354
    switch ($metadata->getTypeOfField($property)) {
    54-
    case 'array':
    55+
    case Type::TARRAY:
    5556
    return new TypeGuess('collection', array(), Guess::MEDIUM_CONFIDENCE);
    56-
    case 'boolean':
    57+
    case Type::BOOLEAN:
    5758
    return new TypeGuess('checkbox', array(), Guess::HIGH_CONFIDENCE);
    58-
    case 'datetime':
    59+
    case Type::DATETIME:
    60+
    case Type::DATETIMETZ:
    5961
    case 'vardatetime':
    60-
    case 'datetimetz':
    6162
    return new TypeGuess('datetime', array(), Guess::HIGH_CONFIDENCE);
    62-
    case 'date':
    63+
    case Type::DATE:
    6364
    return new TypeGuess('date', array(), Guess::HIGH_CONFIDENCE);
    64-
    case 'time':
    65+
    case Type::TIME:
    6566
    return new TypeGuess('time', array(), Guess::HIGH_CONFIDENCE);
    66-
    case 'decimal':
    67-
    case 'float':
    67+
    case Type::DECIMAL:
    68+
    case Type::FLOAT:
    6869
    return new TypeGuess('number', array(), Guess::MEDIUM_CONFIDENCE);
    69-
    case 'integer':
    70-
    case 'bigint':
    71-
    case 'smallint':
    70+
    case Type::INTEGER:
    71+
    case Type::BIGINT:
    72+
    case Type::SMALLINT:
    7273
    return new TypeGuess('integer', array(), Guess::MEDIUM_CONFIDENCE);
    73-
    case 'string':
    74+
    case Type::STRING:
    7475
    return new TypeGuess('text', array(), Guess::MEDIUM_CONFIDENCE);
    75-
    case 'text':
    76+
    case Type::TEXT:
    7677
    return new TypeGuess('textarea', array(), Guess::MEDIUM_CONFIDENCE);
    7778
    default:
    7879
    return new TypeGuess('text', array(), Guess::LOW_CONFIDENCE);
    @@ -95,7 +96,7 @@ public function guessRequired($class, $property)
    9596

    9697
    // Check whether the field exists and is nullable or not
    9798
    if ($classMetadata->hasField($property)) {
    98-
    if (!$classMetadata->isNullable($property)) {
    99+
    if (!$classMetadata->isNullable($property) && Type::BOOLEAN !== $classMetadata->getTypeOfField($property)) {
    99100
    return new ValueGuess(true, Guess::HIGH_CONFIDENCE);
    100101
    }
    101102

    @@ -130,7 +131,7 @@ public function guessMaxLength($class, $property)
    130131
    return new ValueGuess($mapping['length'], Guess::HIGH_CONFIDENCE);
    131132
    }
    132133

    133-
    if (in_array($ret[0]->getTypeOfField($property), array('decimal', 'float'))) {
    134+
    if (in_array($ret[0]->getTypeOfField($property), array(Type::DECIMAL, Type::FLOAT))) {
    134135
    return new ValueGuess(null, Guess::MEDIUM_CONFIDENCE);
    135136
    }
    136137
    }
    @@ -143,7 +144,7 @@ public function guessPattern($class, $property)
    143144
    {
    144145
    $ret = $this->getMetadata($class);
    145146
    if ($ret && $ret[0]->hasField($property) && !$ret[0]->hasAssociation($property)) {
    146-
    if (in_array($ret[0]->getTypeOfField($property), array('decimal', 'float'))) {
    147+
    if (in_array($ret[0]->getTypeOfField($property), array(Type::DECIMAL, Type::FLOAT))) {
    147148
    return new ValueGuess(null, Guess::MEDIUM_CONFIDENCE);
    148149
    }
    149150
    }

    src/Symfony/Component/BrowserKit/Client.php

    Lines changed: 1 addition & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -347,8 +347,7 @@ public function request($method, $uri, array $parameters = array(), array $files
    347347
    */
    348348
    protected function doRequestInProcess($request)
    349349
    {
    350-
    // We set the TMPDIR (for Macs) and TEMP (for Windows), because on these platforms the temp directory changes based on the user.
    351-
    $process = new PhpProcess($this->getScript($request), null, array('TMPDIR' => sys_get_temp_dir(), 'TEMP' => sys_get_temp_dir()));
    350+
    $process = new PhpProcess($this->getScript($request), null, null);
    352351
    $process->run();
    353352

    354353
    if (!$process->isSuccessful() || !preg_match('/^O\:\d+\:/', $process->getOutput())) {

    src/Symfony/Component/BrowserKit/composer.json

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -20,7 +20,7 @@
    2020
    "symfony/dom-crawler": "~2.0,>=2.0.5|~3.0.0"
    2121
    },
    2222
    "require-dev": {
    23-
    "symfony/process": "~2.0,>=2.0.5|~3.0.0",
    23+
    "symfony/process": "~2.3.34|~2.7,>=2.7.6|~3.0.0",
    2424
    "symfony/css-selector": "~2.0,>=2.0.5|~3.0.0"
    2525
    },
    2626
    "suggest": {

    src/Symfony/Component/ClassLoader/ClassCollectionLoader.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -283,7 +283,7 @@ private static function getClassHierarchy(\ReflectionClass $class)
    283283

    284284
    $traits = array();
    285285

    286-
    if (function_exists('get_declared_traits')) {
    286+
    if (method_exists('ReflectionClass', 'getTraits')) {
    287287
    foreach ($classes as $c) {
    288288
    foreach (self::resolveDependencies(self::computeTraitDeps($c), $c) as $trait) {
    289289
    if ($trait !== $c) {

    src/Symfony/Component/Console/Style/SymfonyStyle.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -173,7 +173,7 @@ public function comment($message)
    173173
    */
    174174
    public function success($message)
    175175
    {
    176-
    $this->block($message, 'OK', 'fg=white;bg=green', ' ', true);
    176+
    $this->block($message, 'OK', 'fg=black;bg=green', ' ', true);
    177177
    }
    178178

    179179
    /**

    src/Symfony/Component/DependencyInjection/ContainerBuilder.php

    Lines changed: 3 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -973,7 +973,9 @@ public function createService(Definition $definition, $id, $tryProxy = true)
    973973
    public function resolveServices($value)
    974974
    {
    975975
    if (is_array($value)) {
    976-
    $value = array_map(array($this, 'resolveServices'), $value);
    976+
    foreach ($value as $k => $v) {
    977+
    $value[$k] = $this->resolveServices($v);
    978+
    }
    977979
    } elseif ($value instanceof Reference) {
    978980
    $value = $this->get((string) $value, $value->getInvalidBehavior());
    979981
    } elseif ($value instanceof Definition) {

    src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToStringTransformer.php

    Lines changed: 13 additions & 15 deletions
    Original file line numberDiff line numberDiff line change
    @@ -86,7 +86,7 @@ public function __construct($inputTimezone = null, $outputTimezone = null, $form
    8686
    * Transforms a DateTime object into a date string with the configured format
    8787
    * and timezone.
    8888
    *
    89-
    * @param \DateTime|\DateTimeInterface $dateTime A DateTime object
    89+
    * @param \DateTime|\DateTimeInterface $value A DateTime object
    9090
    *
    9191
    * @return string A value as produced by PHP's date() function
    9292
    *
    @@ -138,21 +138,21 @@ public function reverseTransform($value)
    138138
    throw new TransformationFailedException('Expected a string.');
    139139
    }
    140140

    141-
    try {
    142-
    $outputTz = new \DateTimeZone($this->outputTimezone);
    143-
    $dateTime = \DateTime::createFromFormat($this->parseFormat, $value, $outputTz);
    141+
    $outputTz = new \DateTimeZone($this->outputTimezone);
    142+
    $dateTime = \DateTime::createFromFormat($this->parseFormat, $value, $outputTz);
    144143

    145-
    $lastErrors = \DateTime::getLastErrors();
    144+
    $lastErrors = \DateTime::getLastErrors();
    146145

    147-
    if (0 < $lastErrors['warning_count'] || 0 < $lastErrors['error_count']) {
    148-
    throw new TransformationFailedException(
    149-
    implode(', ', array_merge(
    150-
    array_values($lastErrors['warnings']),
    151-
    array_values($lastErrors['errors'])
    152-
    ))
    153-
    );
    154-
    }
    146+
    if (0 < $lastErrors['warning_count'] || 0 < $lastErrors['error_count']) {
    147+
    throw new TransformationFailedException(
    148+
    implode(', ', array_merge(
    149+
    array_values($lastErrors['warnings']),
    150+
    array_values($lastErrors['errors'])
    151+
    ))
    152+
    );
    153+
    }
    155154

    155+
    try {
    156156
    // On PHP versions < 5.3.7 we need to emulate the pipe operator
    157157
    // and reset parts not given in the format to their equivalent
    158158
    // of the UNIX base timestamp.
    @@ -220,8 +220,6 @@ public function reverseTransform($value)
    220220
    if ($this->inputTimezone !== $this->outputTimezone) {
    221221
    $dateTime->setTimezone(new \DateTimeZone($this->inputTimezone));
    222222
    }
    223-
    } catch (TransformationFailedException $e) {
    224-
    throw $e;
    225223
    } catch (\Exception $e) {
    226224
    throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
    227225
    }

    src/Symfony/Component/HttpFoundation/IpUtils.php

    Lines changed: 7 additions & 6 deletions
    Original file line numberDiff line numberDiff line change
    @@ -57,18 +57,19 @@ public static function checkIp($requestIp, $ips)
    5757
    * @param string $requestIp IPv4 address to check
    5858
    * @param string $ip IPv4 address or subnet in CIDR notation
    5959
    *
    60-
    * @return bool Whether the IP is valid
    60+
    * @return bool Whether the request IP matches the IP, or whether the request IP is within the CIDR subnet.
    6161
    */
    6262
    public static function checkIp4($requestIp, $ip)
    6363
    {
    6464
    if (false !== strpos($ip, '/')) {
    65-
    if ('0.0.0.0/0' === $ip) {
    66-
    return true;
    67-
    }
    68-
    6965
    list($address, $netmask) = explode('/', $ip, 2);
    7066

    71-
    if ($netmask < 1 || $netmask > 32) {
    67+
    if ($netmask === '0') {
    68+
    // Ensure IP is valid - using ip2long below implicitly validates, but we need to do it manually here
    69+
    return filter_var($address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
    70+
    }
    71+
    72+
    if ($netmask < 0 || $netmask > 32) {
    7273
    return false;
    7374
    }
    7475
    } else {

    src/Symfony/Component/HttpFoundation/Tests/IpUtilsTest.php

    Lines changed: 3 additions & 3 deletions
    Original file line numberDiff line numberDiff line change
    @@ -30,13 +30,13 @@ public function testIpv4Provider()
    3030
    array(true, '192.168.1.1', '192.168.1.1/1'),
    3131
    array(true, '192.168.1.1', '192.168.1.0/24'),
    3232
    array(false, '192.168.1.1', '1.2.3.4/1'),
    33-
    array(false, '192.168.1.1', '192.168.1/33'),
    33+
    array(false, '192.168.1.1', '192.168.1.1/33'), // invalid subnet
    3434
    array(true, '192.168.1.1', array('1.2.3.4/1', '192.168.1.0/24')),
    3535
    array(true, '192.168.1.1', array('192.168.1.0/24', '1.2.3.4/1')),
    3636
    array(false, '192.168.1.1', array('1.2.3.4/1', '4.3.2.1/1')),
    3737
    array(true, '1.2.3.4', '0.0.0.0/0'),
    38-
    array(false, '1.2.3.4', '256.256.256/0'),
    39-
    array(false, '1.2.3.4', '192.168.1.0/0'),
    38+
    array(true, '1.2.3.4', '192.168.1.0/0'),
    39+
    array(false, '1.2.3.4', '256.256.256/0'), // invalid CIDR notation
    4040
    );
    4141
    }
    4242

    src/Symfony/Component/HttpKernel/Tests/Fragment/EsiFragmentRendererTest.php

    Lines changed: 0 additions & 6 deletions
    Original file line numberDiff line numberDiff line change
    @@ -19,12 +19,6 @@
    1919

    2020
    class EsiFragmentRendererTest extends \PHPUnit_Framework_TestCase
    2121
    {
    22-
    public function testRenderFallbackToInlineStrategyIfNoRequest()
    23-
    {
    24-
    $strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy(true));
    25-
    $strategy->render('/', Request::create('/'));
    26-
    }
    27-
    2822
    public function testRenderFallbackToInlineStrategyIfEsiNotSupported()
    2923
    {
    3024
    $strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy(true));

    src/Symfony/Component/Process/PhpProcess.php

    Lines changed: 6 additions & 6 deletions
    Original file line numberDiff line numberDiff line change
    @@ -27,13 +27,13 @@ class PhpProcess extends Process
    2727
    /**
    2828
    * Constructor.
    2929
    *
    30-
    * @param string $script The PHP script to run (as a string)
    31-
    * @param string $cwd The working directory
    32-
    * @param array $env The environment variables
    33-
    * @param int $timeout The timeout in seconds
    34-
    * @param array $options An array of options for proc_open
    30+
    * @param string $script The PHP script to run (as a string)
    31+
    * @param string|null $cwd The working directory or null to use the working dir of the current PHP process
    32+
    * @param array|null $env The environment variables or null to use the same environment as the current PHP process
    33+
    * @param int $timeout The timeout in seconds
    34+
    * @param array $options An array of options for proc_open
    3535
    */
    36-
    public function __construct($script, $cwd = null, array $env = array(), $timeout = 60, array $options = array())
    36+
    public function __construct($script, $cwd = null, array $env = null, $timeout = 60, array $options = array())
    3737
    {
    3838
    $executableFinder = new PhpExecutableFinder();
    3939
    if (false === $php = $executableFinder->find()) {

    src/Symfony/Component/Process/Process.php

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -131,7 +131,7 @@ class Process
    131131
    *
    132132
    * @param string $commandline The command line to run
    133133
    * @param string|null $cwd The working directory or null to use the working dir of the current PHP process
    134-
    * @param array|null $env The environment variables or null to inherit
    134+
    * @param array|null $env The environment variables or null to use the same environment as the current PHP process
    135135
    * @param string|null $input The input
    136136
    * @param int|float|null $timeout The timeout in seconds or null to disable
    137137
    * @param array $options An array of options for proc_open
    @@ -1030,7 +1030,7 @@ public function setEnv(array $env)
    10301030

    10311031
    $this->env = array();
    10321032
    foreach ($env as $key => $value) {
    1033-
    $this->env[(binary) $key] = (binary) $value;
    1033+
    $this->env[$key] = (string) $value;
    10341034
    }
    10351035

    10361036
    return $this;

    src/Symfony/Component/PropertyAccess/PropertyPath.php

    Lines changed: 0 additions & 18 deletions
    Original file line numberDiff line numberDiff line change
    @@ -36,13 +36,6 @@ class PropertyPath implements \IteratorAggregate, PropertyPathInterface
    3636
    */
    3737
    private $elements = array();
    3838

    39-
    /**
    40-
    * The singular forms of the elements in the property path.
    41-
    *
    42-
    * @var array
    43-
    */
    44-
    private $singulars = array();
    45-
    4639
    /**
    4740
    * The number of elements in the property path.
    4841
    *
    @@ -79,7 +72,6 @@ public function __construct($propertyPath)
    7972
    if ($propertyPath instanceof self) {
    8073
    /* @var PropertyPath $propertyPath */
    8174
    $this->elements = $propertyPath->elements;
    82-
    $this->singulars = $propertyPath->singulars;
    8375
    $this->length = $propertyPath->length;
    8476
    $this->isIndex = $propertyPath->isIndex;
    8577
    $this->pathAsString = $propertyPath->pathAsString;
    @@ -115,16 +107,7 @@ public function __construct($propertyPath)
    115107
    $this->isIndex[] = true;
    116108
    }
    117109

    118-
    $pos = false;
    119-
    $singular = null;
    120-
    121-
    if (false !== $pos) {
    122-
    $singular = substr($element, $pos + 1);
    123-
    $element = substr($element, 0, $pos);
    124-
    }
    125-
    126110
    $this->elements[] = $element;
    127-
    $this->singulars[] = $singular;
    128111

    129112
    $position += strlen($matches[1]);
    130113
    $remaining = $matches[4];
    @@ -173,7 +156,6 @@ public function getParent()
    173156
    --$parent->length;
    174157
    $parent->pathAsString = substr($parent->pathAsString, 0, max(strrpos($parent->pathAsString, '.'), strrpos($parent->pathAsString, '[')));
    175158
    array_pop($parent->elements);
    176-
    array_pop($parent->singulars);
    177159
    array_pop($parent->isIndex);
    178160

    179161
    return $parent;

    src/Symfony/Component/VarDumper/Caster/Caster.php

    Lines changed: 2 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -54,6 +54,8 @@ public static function castObject($obj, \ReflectionClass $reflector)
    5454
    foreach ($p as $i => $k) {
    5555
    if (!isset($k[0]) || ("\0" !== $k[0] && !$reflector->hasProperty($k))) {
    5656
    $p[$i] = self::PREFIX_DYNAMIC.$k;
    57+
    } elseif (isset($k[16]) && "\0" === $k[16] && 0 === strpos($k, "\0class@anonymous\0")) {
    58+
    $p[$i] = "\0anonymous-".$reflector->name.strrchr($k, "\0");
    5759
    }
    5860
    }
    5961
    $a = array_combine($p, $a);

    src/Symfony/Component/VarDumper/Caster/ReflectionCaster.php

    Lines changed: 3 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -114,6 +114,9 @@ public static function castFunctionAbstract(\ReflectionFunctionAbstract $c, arra
    114114
    'this' => 'getClosureThis',
    115115
    ));
    116116

    117+
    if (isset($a[$prefix.'returnType'])) {
    118+
    $a[$prefix.'returnType'] = (string) $a[$prefix.'returnType'];
    119+
    }
    117120
    if (isset($a[$prefix.'this'])) {
    118121
    $a[$prefix.'this'] = new CutStub($a[$prefix.'this']);
    119122
    }

    src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php

    Lines changed: 4 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -223,9 +223,12 @@ protected function castObject(Stub $stub, $isNested)
    223223
    $obj = $stub->value;
    224224
    $class = $stub->class;
    225225

    226+
    if (isset($class[15]) && "\0" === $class[15] && 0 === strpos($class, "class@anonymous\x00")) {
    227+
    $class = get_parent_class($class);
    228+
    $stub->class = 'anonymous-'.$class;
    229+
    }
    226230
    if (isset($this->classInfo[$class])) {
    227231
    $classInfo = $this->classInfo[$class];
    228-
    $stub->class = $classInfo[0];
    229232
    } else {
    230233
    $classInfo = array(
    231234
    $class,

    0 commit comments

    Comments
     (0)
    0