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

Skip to content

Commit 86b99ab

Browse files
Merge branch '2.3' into 2.7
* 2.3: [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 [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/Process/Process.php src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorCollectionTest.php src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php
2 parents 8403028 + 297a017 commit 86b99ab

File tree

12 files changed

+55
-78
lines changed

12 files changed

+55
-78
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
@@ -327,8 +327,7 @@ public function request($method, $uri, array $parameters = array(), array $files
327327
*/
328328
protected function doRequestInProcess($request)
329329
{
330-
// We set the TMPDIR (for Macs) and TEMP (for Windows), because on these platforms the temp directory changes based on the user.
331-
$process = new PhpProcess($this->getScript($request), null, array('TMPDIR' => sys_get_temp_dir(), 'TEMP' => sys_get_temp_dir()));
330+
$process = new PhpProcess($this->getScript($request), null, null);
332331
$process->run();
333332

334333
if (!$process->isSuccessful() || !< 10000 span class=pl-en>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"
2121
},
2222
"require-dev": {
23-
"symfony/process": "~2.0,>=2.0.5",
23+
"symfony/process": "~2.3.34|~2.7,>=2.7.6",
2424
"symfony/css-selector": "~2.0,>=2.0.5"
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/DependencyInjection/ContainerBuilder.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,9 @@ public function createService(Definition $definition, $id, $tryProxy = true)
938938
public function resolveServices($value)
939939
{
940940
if (is_array($value)) {
941-
$value = array_map(array($this, 'resolveServices'), $value);
941+
foreach ($value as $k => $v) {
942+
$value[$k] = $this->resolveServices($v);
943+
}
942944
} elseif ($value instanceof Reference) {
943945
$value = $this->get((string) $value, $value->getInvalidBehavior());
944946
} 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()) {

0 commit comments

Comments
 (0)
0