Skip to content

Commit 1d8d43b

Browse files
Merge branch '2.7' into 2.8
* 2.7: [VarDumper] Fix tests on PHP 7 [DomCrawler] Clarify the value returned by getPhpFiles() [DependencyInjection] Fix symfony#16461 Let Container::set() replace existing aliases avoid (string) catchable fatal error for instances of __PHP_Incomplete_Class remove unnecessary retrieval and setting of data avoid (string) catchable fatal error for __PHP_Incomplete_Class instances sendContent return as parent. [FrameworkBundle] Fix a typo Added more exceptions to singularify method
2 parents 9e598a4 + ec7b3f2 commit 1d8d43b

File tree

13 files changed

+83
-29
lines changed

13 files changed

+83
-29
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ protected function configure()
4747
))
4848
->setDescription('Updates the translation file')
4949
->setHelp(<<<'EOF'
50-
The <info>%command.name%</info> command extract translation strings from templates
50+
The <info>%command.name%</info> command extracts translation strings from templates
5151
of a given bundle or the app folder. It can display them or merge the new ones into the translation files.
52+
5253
When new translation strings are found it can automatically add a prefix to the translation
5354
message.
5455

src/Symfony/Component/DependencyInjection/Container.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ public function set($id, $service, $scope = self::SCOPE_CONTAINER)
200200
$this->scopedServices[$scope][$id] = $service;
201201
}
202202

203+
if (isset($this->aliases[$id])) {
204+
unset($this->aliases[$id]);
205+
}
206+
203207
$this->services[$id] = $service;
204208

205209
if (method_exists($this, $method = 'synchronize'.strtr($id, $this->underscoreMap).'Service')) {

src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,16 @@ public function testAddAliases()
253253
$this->assertTrue(isset($aliases['foobar']));
254254
}
255255

256+
public function testSetReplacesAlias()
257+
{
258+
$builder = new ContainerBuilder();
259+
$builder->setAlias('alias', 'aliased');
260+
$builder->set('aliased', new \stdClass());
261+
262+
$builder->set('alias', $foo = new \stdClass());
263+
$this->assertSame($foo, $builder->get('alias'), '->set() replaces an existing alias');
264+
}
265+
256266
public function testAddGetCompilerPass()
257267
{
258268
$builder = new ContainerBuilder();

src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,14 @@ public function testSetAlsoCallsSynchronizeService()
192192
$this->assertTrue($c->synchronized, '->set() calls synchronize*Service() if it is defined for the service');
193193
}
194194

195+
public function testSetReplacesAlias()
196+
{
197+
$c = new ProjectServiceContainer();
198+
199+
$c->set('alias', $foo = new \stdClass());
200+
$this->assertSame($foo, $c->get('alias'), '->set() replaces an existing alias');
201+
}
202+
195203
public function testGet()
196204
{
197205
$sc = new ProjectServiceContainer();

src/Symfony/Component/DomCrawler/Form.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,12 @@ public function getPhpValues()
157157
*
158158
* This method converts fields with the array notation
159159
* (like foo[bar] to arrays) like PHP does.
160+
* The returned array is consistent with the array for field values
161+
* (@see getPhpValues), rather than uploaded files found in $_FILES.
162+
* For a compound file field foo[bar] it will create foo[bar][name],
163+
* instead of foo[name][bar] which would be found in $_FILES.
160164
*
161-
* @return array An array of field values.
165+
* @return array An array of file field values.
162166
*/
163167
public function getPhpFiles()
164168
{

src/Symfony/Component/Form/Extension/Csrf/EventListener/CsrfValidationListener.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,10 @@ public function __construct($fieldName, $tokenManager, $tokenId, $errorMessage,
9494
public function preSubmit(FormEvent $event)
9595
{
9696
$form = $event->getForm();
97-
$data = $event->getData();
9897

9998
if ($form->isRoot() && $form->getConfig()->getOption('compound')) {
99+
$data = $event->getData();
100+
100101
if (!isset($data[$this->fieldName]) || !$this->tokenManager->isTokenValid(new CsrfToken($this->tokenId, $data[$this->fieldName]))) {
101102
$errorMessage = $this->errorMessage;
102103

@@ -109,10 +110,9 @@ public function preSubmit(FormEvent $event)
109110

110111
if (is_array($data)) {
111112
unset($data[$this->fieldName]);
113+
$event->setData($data);
112114
}
113115
}
114-
115-
$event->setData($data);
116116
}
117117

118118
/**

src/Symfony/Component/HttpFoundation/BinaryFileResponse.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ class BinaryFileResponse extends Response
2727
{
2828
protected static $trustXSendfileTypeHeader = false;
2929

30+
/**
31+
* @var File
32+
*/
3033
protected $file;
3134
protected $offset;
3235
protected $maxlen;
@@ -180,7 +183,7 @@ public function prepare(Request $request)
180183
$this->headers->set('Content-Type', $this->file->getMimeType() ?: 'application/octet-stream');
181184
}
182185

183-
if ('HTTP/1.0' != $request->server->get('SERVER_PROTOCOL')) {
186+
if ('HTTP/1.0' !== $request->server->get('SERVER_PROTOCOL')) {
184187
$this->setProtocolVersion('1.1');
185188
}
186189

@@ -197,17 +200,17 @@ public function prepare(Request $request)
197200
if (false === $path) {
198201
$path = $this->file->getPathname();
199202
}
200-
if (strtolower($type) == 'x-accel-redirect') {
203+
if (strtolower($type) === 'x-accel-redirect') {
201204
// Do X-Accel-Mapping substitutions.
202205
// @link http://wiki.nginx.org/X-accel#X-Accel-Redirect
203206
foreach (explode(',', $request->headers->get('X-Accel-Mapping', '')) as $mapping) {
204207
$mapping = explode('=', $mapping, 2);
205208

206-
if (2 == count($mapping)) {
209+
if (2 === count($mapping)) {
207210
$pathPrefix = trim($mapping[0]);
208211
$location = trim($mapping[1]);
209212

210-
if (substr($path, 0, strlen($pathPrefix)) == $pathPrefix) {
213+
if (substr($path, 0, strlen($pathPrefix)) === $pathPrefix) {
211214
$path = $location.substr($path, strlen($pathPrefix));
212215
break;
213216
}
@@ -218,7 +221,7 @@ public function prepare(Request $request)
218221
$this->maxlen = 0;
219222
} elseif ($request->headers->has('Range')) {
220223
// Process the range headers.
221-
if (!$request->headers->has('If-Range') || $this->getEtag() == $request->headers->get('If-Range')) {
224+
if (!$request->headers->has('If-Range') || $this->getEtag() === $request->headers->get('If-Range')) {
222225
$range = $request->headers->get('Range');
223226
$fileSize = $this->file->getSize();
224227

@@ -253,17 +256,17 @@ public function prepare(Request $request)
253256

254257
/**
255258
* Sends the file.
259+
*
260+
* {@inheritdoc}
256261
*/
257262
public function sendContent()
258263
{
259264
if (!$this->isSuccessful()) {
260-
parent::sendContent();
261-
262-
return;
265+
return parent::sendContent();
263266
}
264267

265268
if (0 === $this->maxlen) {
266-
return;
269+
return $this;
267270
}
268271

269272
$out = fopen('php://output', 'wb');
@@ -277,6 +280,8 @@ public function sendContent()
277280
if ($this->deleteFileAfterSend) {
278281
unlink($this->file->getPathname());
279282
}
283+
284+
return $this;
280285
}
281286

282287
/**

src/Symfony/Component/HttpKernel/DataCollector/Util/ValueExporter.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ public function exportValue($value, $depth = 1, $deep = false)
3535
return sprintf('Object(%s)', get_class($value));
3636
}
3737

38+
if ($value instanceof \__PHP_Incomplete_Class) {
39+
return sprintf('__PHP_Incomplete_Class(%s)', $this->getClassNameFromIncomplete($value));
40+
}
41+
3842
if (is_array($value)) {
3943
if (empty($value)) {
4044
return '[]';
@@ -75,4 +79,11 @@ public function exportValue($value, $depth = 1, $deep = false)
7579

7680
return (string) $value;
7781
}
82+
83+
private function getClassNameFromIncomplete(\__PHP_Incomplete_Class $value)
84+
{
85+
$array = new \ArrayObject($value);
86+
87+
return $array['__PHP_Incomplete_Class_Name'];
88+
}
7889
}

src/Symfony/Component/HttpKernel/Tests/DataCollector/Util/ValueExporterTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,12 @@ public function testDateTimeImmutable()
3939
$dateTime = new \DateTimeImmutable('2014-06-10 07:35:40', new \DateTimeZone('UTC'));
4040
$this->assertSame('Object(DateTimeImmutable) - 2014-06-10T07:35:40+0000', $this->valueExporter->exportValue($dateTime));
4141
}
42+
43+
public function testIncompleteClass()
44+
{
45+
$foo = new \__PHP_Incomplete_Class();
46+
$array = new \ArrayObject($foo);
47+
$array['__PHP_Incomplete_Class_Name'] = 'AppBundle/Foo';
48+
$this->assertSame('__PHP_Incomplete_Class(AppBundle/Foo)', $this->valueExporter->exportValue($foo));
49+
}
4250
}

src/Symfony/Component/PropertyAccess/StringUtil.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ class StringUtil
3939
// nebulae (nebula)
4040
array('ea', 2, true, true, 'a'),
4141

42+
// services (service)
43+
array('secivres', 8, true, true, 'service'),
44+
4245
// mice (mouse), lice (louse)
4346
array('eci', 3, false, true, 'ouse'),
4447

@@ -66,6 +69,12 @@ class StringUtil
6669
// movies (movie)
6770
array('seivom', 6, true, true, 'movie'),
6871

72+
// news (news)
73+
array('swen', 4, true, true, 'news'),
74+
75+
// series (series)
76+
array('seires', 6, true, true, 'series'),
77+
6978
// babies (baby)
7079
array('sei', 3, false, true, 'y'),
7180

0 commit comments

Comments
 (0)