Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1750330

Browse filesBrowse files
committed
Merge branch '2.6' into 2.7
* 2.6: [Validator] remove partial deprecation annotation Updated UPGRADE-2.4.md [Form] Support DateTimeImmutable in transform() [Form] add test to avoid regression of #14891 without this change allways the legacy code get called [Form] Fix call to removed method (BC broken in 2.3) [HttpFoundation] Get response content as resource several times for PHP >= 5.6 Improved duplicated code in FileLocator
2 parents acb5528 + 49d942a commit 1750330
Copy full SHA for 1750330
Expand file treeCollapse file tree

17 files changed

+203
-55
lines changed

‎UPGRADE-2.4.md

Copy file name to clipboardExpand all lines: UPGRADE-2.4.md
+41Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,44 @@ Form
77
* The constructor parameter `$precision` in `IntegerToLocalizedStringTransformer`
88
is now ignored completely, because a precision does not make sense for
99
integers.
10+
11+
EventDispatcher
12+
----------------
13+
14+
* The `getDispatcher()` and `getName()` methods from `Symfony\Component\EventDispatcher\Event`
15+
are deprecated, the event dispatcher instance and event name can be received in the listener call instead.
16+
17+
Before:
18+
19+
```php
20+
use Symfony\Component\EventDispatcher\Event;
21+
22+
class Foo
23+
{
24+
public function myFooListener(Event $event)
25+
{
26+
$dispatcher = $event->getDispatcher();
27+
$eventName = $event->getName();
28+
$dispatcher->dispatch('log', $event);
29+
30+
// ... more code
31+
}
32+
}
33+
```
34+
35+
After:
36+
37+
```php
38+
use Symfony\Component\EventDispatcher\Event;
39+
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
40+
41+
class Foo
42+
{
43+
public function myFooListener(Event $event, $eventName, EventDispatcherInterface $dispatcher)
44+
{
45+
$dispatcher->dispatch('log', $event);
46+
47+
// ... more code
48+
}
49+
}
50+
```

‎src/Symfony/Component/Config/FileLocator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/FileLocator.php
+8-8Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ public function locate($name, $currentPath = null, $first = true)
4747
return $name;
4848
}
4949

50-
$filepaths = array();
51-
if (null !== $currentPath && file_exists($file = $currentPath.DIRECTORY_SEPARATOR.$name)) {
52-
if (true === $first) {
53-
return $file;
54-
}
55-
$filepaths[] = $file;
50+
$paths = $this->paths;
51+
52+
if (null !== $currentPath) {
53+
array_unshift($paths, $currentPath);
5654
}
5755

58-
foreach ($this->paths as $path) {
56+
$filepaths = array();
57+
58+
foreach ($paths as $path) {
5959
if (file_exists($file = $path.DIRECTORY_SEPARATOR.$name)) {
6060
if (true === $first) {
6161
return $file;
@@ -65,7 +65,7 @@ public function locate($name, $currentPath = null, $first = true)
6565
}
6666

6767
if (!$filepaths) {
68-
throw new \InvalidArgumentException(sprintf('The file "%s" does not exist (in: %s%s).', $name, null !== $currentPath ? $currentPath.', ' : '', implode(', ', $this->paths)));
68+
throw new \InvalidArgumentException(sprintf('The file "%s" does not exist (in: %s).', $name, implode(', ', $paths)));
6969
}
7070

7171
return array_values(array_unique($filepaths));

‎src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToArrayTransformer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToArrayTransformer.php
+8-5Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function __construct($inputTimezone = null, $outputTimezone = null, array
5151
/**
5252
* Transforms a normalized date into a localized date.
5353
*
54-
* @param \DateTime $dateTime Normalized date.
54+
* @param \DateTime|\DateTimeInterface $dateTime A DateTime object
5555
*
5656
* @return array Localized date.
5757
*
@@ -72,14 +72,17 @@ public function transform($dateTime)
7272
), array_flip($this->fields));
7373
}
7474

75-
if (!$dateTime instanceof \DateTime) {
76-
throw new TransformationFailedException('Expected a \DateTime.');
75+
if (!$dateTime instanceof \DateTime && !$dateTime instanceof \DateTimeInterface) {
76+
throw new TransformationFailedException('Expected a \DateTime or \DateTimeInterface.');
7777
}
7878

79-
$dateTime = clone $dateTime;
8079
if ($this->inputTimezone !== $this->outputTimezone) {
80+
if (!$dateTime instanceof \DateTimeImmutable) {
81+
$dateTime = clone $dateTime;
82+
}
83+
8184
try {
82-
$dateTime->setTimezone(new \DateTimeZone($this->outputTimezone));
85+
$dateTime = $dateTime->setTimezone(new \DateTimeZone($this->outputTimezone));
8386
} catch (\Exception $e) {
8487
throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
8588
}

‎src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformer.php
+4-10Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function __construct($inputTimezone = null, $outputTimezone = null, $date
7070
/**
7171
* Transforms a normalized date into a localized date string/array.
7272
*
73-
* @param \DateTime $dateTime Normalized date.
73+
* @param \DateTime|\DateTimeInterface $dateTime A DateTime object
7474
*
7575
* @return string|array Localized date string/array.
7676
*
@@ -84,17 +84,11 @@ public function transform($dateTime)
8484
return '';
8585
}
8686

87-
if (!$dateTime instanceof \DateTime) {
88-
throw new TransformationFailedException('Expected a \DateTime.');
87+
if (!$dateTime instanceof \DateTime && !$dateTime instanceof \DateTimeInterface) {
88+
throw new TransformationFailedException('Expected a \DateTime or \DateTimeInterface.');
8989
}
9090

91-
// convert time to UTC before passing it to the formatter
92-
$dateTime = clone $dateTime;
93-
if ('UTC' !== $this->inputTimezone) {
94-
$dateTime->setTimezone(new \DateTimeZone('UTC'));
95-
}
96-
97-
$value = $this->getIntlDateFormatter()->format((int) $dateTime->format('U'));
91+
$value = $this->getIntlDateFormatter()->format($dateTime->getTimestamp());
9892

9993
if (intl_get_error_code() != 0) {
10094
throw new TransformationFailedException(intl_get_error_message());

‎src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToRfc3339Transformer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToRfc3339Transformer.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ public function transform($dateTime)
2727
return '';
2828
}
2929

30-
if (!$dateTime instanceof \DateTime) {
31-
throw new TransformationFailedException('Expected a \DateTime.');
30+
if (!$dateTime instanceof \DateTime && !$dateTime instanceof \DateTimeInterface) {
31+
throw new TransformationFailedException('Expected a \DateTime or \DateTimeInterface.');
3232
}
3333

3434
if ($this->inputTimezone !== $this->outputTimezone) {
3535
$dateTime = clone $dateTime;
36-
$dateTime->setTimezone(new \DateTimeZone($this->outputTimezone));
36+
$dateTime = $dateTime->setTimezone(new \DateTimeZone($this->outputTimezone));
3737
}
3838

3939
return preg_replace('/\+00:00$/', 'Z', $dateTime->format('c'));

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToStringTransformer.php
+8-5Lines changed: 8 additions & 5 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 $value A DateTime object
89+
* @param \DateTime|\DateTimeInterface $dateTime A DateTime object
9090
*
9191
* @return string A value as produced by PHP's date() function
9292
*
@@ -100,13 +100,16 @@ public function transform($value)
100100
return '';
101101
}
102102

103-
if (!$value instanceof \DateTime) {
104-
throw new TransformationFailedException('Expected a \DateTime.');
103+
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
104+
throw new TransformationFailedException('Expected a \DateTime or \DateTimeInterface.');
105+
}
106+
107+
if (!$value instanceof \DateTimeImmutable) {
108+
$value = clone $value;
105109
}
106110

107-
$value = clone $value;
108111
try {
109-
$value->setTimezone(new \DateTimeZone($this->outputTimezone));
112+
$value = $value->setTimezone(new \DateTimeZone($this->outputTimezone));
110113
} catch (\Exception $e) {
111114
throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
112115
}

‎src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToTimestampTransformer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToTimestampTransformer.php
+4-11Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class DateTimeToTimestampTransformer extends BaseDateTimeTransformer
2424
/**
2525
* Transforms a DateTime object into a timestamp in the configured timezone.
2626
*
27-
* @param \DateTime $value A \DateTime object
27+
* @param \DateTime|\DateTimeInterface $dateTime A DateTime object
2828
*
2929
* @return int A timestamp
3030
*
@@ -38,18 +38,11 @@ public function transform($value)
3838
return;
3939
}
4040

41-
if (!$value instanceof \DateTime) {
42-
throw new TransformationFailedException('Expected a \DateTime.');
41+
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
42+
throw new TransformationFailedException('Expected a \DateTime or \DateTimeInterface.');
4343
}
4444

45-
$value = clone $value;
46-
try {
47-
$value->setTimezone(new \DateTimeZone($this->outputTimezone));
48-
} catch (\Exception $e) {
49-
throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
50-
}
51-
52-
return (int) $value->format('U');
45+
return $value->getTimestamp();
5346
}
5447

5548
/**

‎src/Symfony/Component/Form/Extension/Validator/ValidatorExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Validator/ValidatorExtension.php
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ public function __construct($validator)
5959

6060
public function loadTypeGuesser()
6161
{
62-
// 2.4 API
63-
if ($this->validator instanceof LegacyValidatorInterface) {
64-
return new ValidatorTypeGuesser($this->validator->getMetadataFactory());
62+
// 2.5 API
63+
if ($this->validator instanceof ValidatorInterface) {
64+
return new ValidatorTypeGuesser($this->validator);
6565
}
6666

67-
// 2.5 API - ValidatorInterface extends MetadataFactoryInterface
68-
return new ValidatorTypeGuesser($this->validator);
67+
// 2.4 API
68+
return new ValidatorTypeGuesser($this->validator->getMetadataFactory());
6969
}
7070

7171
protected function loadTypeExtensions()

‎src/Symfony/Component/Form/ResolvedFormType.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/ResolvedFormType.php
-5Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,6 @@ public function getInnerType()
9393
*/
9494
public function getTypeExtensions()
9595
{
96-
// BC
97-
if ($this->innerType instanceof AbstractType) {
98-
return $this->innerType->getExtensions();
99-
}
100-
10196
return $this->typeExtensions;
10297
}
10398

‎src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToArrayTransformerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToArrayTransformerTest.php
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,30 @@ public function testTransformDifferentTimezones()
116116
$this->assertSame($output, $transformer->transform($input));
117117
}
118118

119+
public function testTransformDateTimeImmutable()
120+
{
121+
if (PHP_VERSION_ID < 50500) {
122+
$this->markTestSkipped('DateTimeImmutable was introduced in PHP 5.5.0');
123+
}
124+
125+
$transformer = new DateTimeToArrayTransformer('America/New_York', 'Asia/Hong_Kong');
126+
127+
$input = new \DateTimeImmutable('2010-02-03 04:05:06 America/New_York');
128+
129+
$dateTime = new \DateTimeImmutable('2010-02-03 04:05:06 America/New_York');
130+
$dateTime = $dateTime->setTimezone(new \DateTimeZone('Asia/Hong_Kong'));
131+
$output = array(
132+
'year' => (string) (int) $dateTime->format('Y'),
133+
'month' => (string) (int) $dateTime->format('m'),
134+
'day' => (string) (int) $dateTime->format('d'),
135+
'hour' => (string) (int) $dateTime->format('H'),
136+
'minute' => (string) (int) $dateTime->format('i'),
137+
'second' => (string) (int) $dateTime->format('s'),
138+
);
139+
140+
$this->assertSame($output, $transformer->transform($input));
141+
}
142+
119143
/**
120144
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
121145
*/

‎src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,22 @@ public function testTransformWithDifferentPatterns()
141141
$this->assertEquals('02*2010*03 04|05|06', $transformer->transform($this->dateTime));
142142
}
143143

144+
public function testTransformDateTimeImmutableTimezones()
145+
{
146+
if (PHP_VERSION_ID < 50500) {
147+
$this->markTestSkipped('DateTimeImmutable was introduced in PHP 5.5.0');
148+
}
149+
150+
$transformer = new DateTimeToLocalizedStringTransformer('America/New_York', 'Asia/Hong_Kong');
151+
152+
$input = new \DateTimeImmutable('2010-02-03 04:05:06 America/New_York');
153+
154+
$dateTime = clone $input;
155+
$dateTime = $dateTime->setTimezone(new \DateTimeZone('Asia/Hong_Kong'));
156+
157+
$this->assertEquals($dateTime->format('d.m.Y H:i'), $transformer->transform($input));
158+
}
159+
144160
/**
145161
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
146162
*/

‎src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToRfc3339TransformerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToRfc3339TransformerTest.php
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,20 @@ public function testTransform($fromTz, $toTz, $from, $to)
7979
$this->assertSame($to, $transformer->transform(null !== $from ? new \DateTime($from) : null));
8080
}
8181

82+
/**
83+
* @dataProvider transformProvider
84+
*/
85+
public function testTransformDateTimeImmutable($fromTz, $toTz, $from, $to)
86+
{
87+
if (PHP_VERSION_ID < 50500) {
88+
$this->markTestSkipped('DateTimeImmutable was introduced in PHP 5.5.0');
89+
}
90+
91+
$transformer = new DateTimeToRfc3339Transformer($fromTz, $toTz);
92+
93+
$this->assertSame($to, $transformer->transform(null !== $from ? new \DateTimeImmutable($from) : null));
94+
}
95+
8296
/**
8397
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
8498
*/

‎src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToStringTransformerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToStringTransformerTest.php
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,21 @@ public function testTransformWithDifferentTimezones()
9494
$this->assertEquals($output, $transformer->transform($input));
9595
}
9696

97+
public function testTransformDateTimeImmutable()
98+
{
99+
if (PHP_VERSION_ID < 50500) {
100+
$this->markTestSkipped('DateTimeImmutable was introduced in PHP 5.5.0');
101+
}
102+
103+
$transformer = new DateTimeToStringTransformer('Asia/Hong_Kong', 'America/New_York', 'Y-m-d H:i:s');
104+
105+
$input = new \DateTimeImmutable('2010-02-03 12:05:06 America/New_York');
106+
$output = $input->format('Y-m-d H:i:s');
107+
$input = $input->setTimezone(new \DateTimeZone('Asia/Hong_Kong'));
108+
109+
$this->assertEquals($output, $transformer->transform($input));
110+
}
111+
97112
public function testTransformExpectsDateTime()
98113
{
99114
$transformer = new DateTimeToStringTransformer();

‎src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToTimestampTransformerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToTimestampTransformerTest.php
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,21 @@ public function testTransformFromDifferentTimezone()
5656
$this->assertEquals($output, $transformer->transform($input));
5757
}
5858

59+
public function testTransformDateTimeImmutable()
60+
{
61+
if (PHP_VERSION_ID < 50500) {
62+
$this->markTestSkipped('DateTimeImmutable was introduced in PHP 5.5.0');
63+
}
64+
65+
$transformer = new DateTimeToTimestampTransformer('Asia/Hong_Kong', 'America/New_York');
66+
67+
$input = new \DateTimeImmutable('2010-02-03 04:05:06 America/New_York');
68+
$output = $input->format('U');
69+
$input = $input->setTimezone(new \DateTimeZone('Asia/Hong_Kong'));
70+
71+
$this->assertEquals($output, $transformer->transform($input));
72+
}
73+
5974
public function testTransformExpectsDateTime()
6075
{
6176
$transformer = new DateTimeToTimestampTransformer();

‎src/Symfony/Component/Form/Tests/Extension/Validator/ValidatorExtensionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Validator/ValidatorExtensionTest.php
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ class ValidatorExtensionTest extends \PHPUnit_Framework_TestCase
1717
{
1818
public function test2Dot5ValidationApi()
1919
{
20-
$validator = $this->getMock('Symfony\Component\Validator\Validator\ValidatorInterface');
20+
$validator = $this->getMockBuilder('Symfony\Component\Validator\Validator\RecursiveValidator')
21+
->disableOriginalConstructor()
22+
->getMock();
2123
$metadata = $this->getMockBuilder('Symfony\Component\Validator\Mapping\ClassMetadata')
2224
->disableOriginalConstructor()
2325
->getMock();
@@ -36,6 +38,10 @@ public function test2Dot5ValidationApi()
3638
->method('addPropertyConstraint')
3739
->with('children', $this->isInstanceOf('Symfony\Component\Validator\Constraints\Valid'));
3840

41+
$validator
42+
->expects($this->never())
43+
->method('getMetadataFactory');
44+
3945
$extension = new ValidatorExtension($validator);
4046
$guesser = $extension->loadTypeGuesser();
4147

‎src/Symfony/Component/HttpFoundation/Request.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Request.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,8 +1557,8 @@ public function isMethodSafe()
15571557
*/
15581558
public function getContent($asResource = false)
15591559
{
1560-
if (false === $this->content || (true === $asResource && null !== $this->content)) {
1561-
throw new \LogicException('getContent() can only be called once when using the resource return type.');
1560+
if (PHP_VERSION_ID < 50600 && (false === $this->content || (true === $asResource && null !== $this->content))) {
1561+
throw new \LogicException('getContent() can only be called once when using the resource return type and PHP below 5.6.');
15621562
}
15631563

15641564
if (true === $asResource) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.