10000 Merge branch '4.4' into 5.4 · symfony/symfony@d7b5ea8 · GitHub
[go: up one dir, main page]

Skip to content

Commit d7b5ea8

Browse files
Merge branch '4.4' into 5.4
* 4.4: [HttpKernel] lock when writting profiles Using identical comparison for path validation [Mime] Fix email rendering when having inlined parts that are not related to the content [HttpFoundation] move flushing outside of Response::closeOutputBuffers [FrameworkBundle] Do not throw when describing a factory definition Fix checking result of DateTime::getLastErrors
2 parents e76364c + 5dfb353 commit d7b5ea8

24 files changed

+215
-52
lines changed

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ private function getContainerDefinitionData(Definition $definition, bool $omitTa
245245
if ($factory[0] instanceof Reference) {
246246
$data['factory_service'] = (string) $factory[0];
247247
} elseif ($factory[0] instanceof Definition) {
248-
throw new \InvalidArgumentException('Factory is not describable.');
248+
$data['factory_class'] = $factory[0]->getClass() ?? 'not configured';
249249
} else {
250250
$data['factory_class'] = $factory[0];
251251
}

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ protected function describeContainerDefinition(Definition $definition, array $op
224224
if ($factory[0] instanceof Reference) {
225225
$output .= "\n".'- Factory Service: `'.$factory[0].'`';
226226
} elseif ($factory[0] instanceof Definition) {
227-
throw new \InvalidArgumentException('Factory is not describable.');
227+
$output .= "\n".'- Factory Class: `'.($factory[0]->getClass() ?? 'not configured').'`';
228228
} else {
229229
$output .= "\n".'- Factory Class: `'.$factory[0].'`';
230230
}

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ protected function describeContainerDefinition(Definition $definition, array $op
315315
if ($factory[0] instanceof Reference) {
316316
$tableRows[] = ['Factory Service', $factory[0]];
317317
} elseif ($factory[0] instanceof Definition) {
318-
throw new \InvalidArgumentException('Factory is not describable.');
318+
$tableRows[] = ['Factory Class', $factory[0]->getClass() ?? 'not configured'];
319319
} else {
320320
$tableRows[] = ['Factory Class', $factory[0]];
321321
}

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ private function getContainerDefinitionDocument(Definition $definition, string $
324324
if ($factory[0] instanceof Reference) {
325325
$factoryXML->setAttribute('service', (string) $factory[0]);
326326
} elseif ($factory[0] instanceof Definition) {
327-
throw new \InvalidArgumentException('Factory is not describable.');
327+
$factoryXML->setAttribute('class', $factory[0]->getClass() ?? 'not configured');
328328
} else {
329329
$factoryXML->setAttribute('class', $factory[0]);
330330
}

src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ public static function getContainerDefinitions()
142142
{
143143
$definition1 = new Definition('Full\\Qualified\\Class1');
144144
$definition2 = new Definition('Full\\Qualified\\Class2');
145+
$definition3 = new Definition('Full\\Qualified\\Class3');
145146

146147
return [
147148
'definition_1' => $definition1
@@ -174,6 +175,9 @@ public static function getContainerDefinitions()
174175
->addTag('tag2')
175176
->addMethodCall('setMailer', [new Reference('mailer')])
176177
->setFactory([new Reference('factory.service'), 'get']),
178+
'.definition_3' => $definition3
179+
->setFile('/path/to/file')
180+
->setFactory([new Definition('Full\\Qualified\\FactoryClass'), 'get']),
177181
'definition_without_class' => new Definition(),
178182
];
179183
}

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_services.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@
3434
"parameters": []
3535
}
3636
]
37+
},
38+
".definition_3": {
39+
"class": "Full\\Qualified\\Class3",
40+
"public": false,
41+
"synthetic": false,
42+
"lazy": false,
43+
"shared": true,
44+
"abstract": false,
45+
"autowire": false,
46+
"autoconfigure": false,
47+
"file": "\/path\/to\/file",
48+
"factory_class": "Full\\Qualified\\FactoryClass",
49+
"factory_method": "get",
50+
"tags": []
3751
}
3852
},
3953
"aliases": {

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_services.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ Definitions
2525
- Attr3: val3
2626
- Tag: `tag2`
2727

28+
### .definition_3
29+
30+
- Class: `Full\Qualified\Class3`
31+
- Public: no
32+
- Synthetic: no
33+
- Lazy: no
34+
- Shared: yes
35+
- Abstract: no
36+
- Autowired: no
37+
- Autoconfigured: no
38+
- File: `/path/to/file`
39+
- Factory Class: `Full\Qualified\FactoryClass`
40+
- Factory Method: `get`
41+
2842

2943
Aliases
3044
-------

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_services.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
--------------- ------------------------
88
.alias_2 alias for ".service_2"
99
.definition_2 Full\Qualified\Class2
10-
--------------- ------------------------
10+
.definition_3 Full\Qualified\Class3
11+
--------------- ------------------------
1112

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_services.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
<tag name="tag2"/>
1818
</tags>
1919
</definition>
20+
<definition id=".definition_3" class="Full\Qualified\Class3" public="false" synthetic="false" lazy="false" shared="true" abstract="false" autowired="false" autoconfigured="false" file="/path/to/file">
21+
<factory class="Full\Qualified\FactoryClass" method="get"/>
22+
</definition>
2023
</container>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"class": "Full\\Qualified\\Class3",
3+
"public": false,
4+
"synthetic": false,
5+
"lazy": false,
6+
"shared": true,
7+
"abstract": false,
8+
"autowire": false,
9+
"autoconfigure": false,
10+
"file": "\/path\/to\/file",
11+
"factory_class": "Full\\Qualified\\FactoryClass",
12+
"factory_method": "get",
13+
"tags": []
14+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
- Class: `Full\Qualified\Class3`
2+
- Public: no
3+
- Synthetic: no
4+
- Lazy: no
5+
- Shared: yes
6+
- Abstract: no
7+
- Autowired: no
8+
- Autoconfigured: no
9+
- File: `/path/to/file`
10+
- Factory Class: `Full\Qualified\FactoryClass`
11+
- Factory Method: `get`
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---------------- -----------------------------
2+
 Option   Value 
3+
---------------- -----------------------------
4+
Service ID -
5+
Class Full\Qualified\Class3
6+
Tags -
7+
Public no
8+
Synthetic no
9+
Lazy no
10+
Shared yes
11+
Abstract no
12+
Autowired no
13+
Autoconfigured no
14+
Required File /path/to/file
15+
Factory Class Full\Qualified\FactoryClass
16+
Factory Method get
17+
---------------- -----------------------------
18+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<definition class="Full\Qualified\Class3" public="false" synthetic="false" lazy="false" shared="true" abstract="false" autowired="false" autoconfigured="false" file="/path/to/file">
3+
<factory class="Full\Qualified\FactoryClass" method="get"/>
4+
</definition>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"class": "Full\\Qualified\\Class3",
3+
"public": false,
4+
"synthetic": false,
5+
"lazy": false,
6+
"shared": true,
7+
"abstract": false,
8+
"autowire": false,
9+
"autoconfigure": false,
10+
"arguments": [],
11+
"file": "\/path\/to\/file",
12+
"factory_class": "Full\\Qualified\\FactoryClass",
13+
"factory_method": "get",
14+
"tags": []
15+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
- Class: `Full\Qualified\Class3`
2+
- Public: no
3+
- Synthetic: no
4+
- Lazy: no
5+
- Shared: yes
6+
- Abstract: no
7+
- Autowired: no
8+
- Autoconfigured: no
9+
- Arguments: no
10+
- File: `/path/to/file`
11+
- Factory Class: `Full\Qualified\FactoryClass`
12+
- Factory Method: `get`
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---------------- -----------------------------
2+
 Option   Value 
3+
---------------- -----------------------------
4+
Service ID -
5+
Class Full\Qualified\Class3
6+
Tags -
7+
Public no
8+
Synthetic no
9+
Lazy no
10+
Shared yes
11+
Abstract no
12+
Autowired no
13+
Autoconfigured no
14+
Required File /path/to/file
15+
Factory Class Full\Qualified\FactoryClass
16+
Factory Method get
17+
---------------- -----------------------------
18+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<definition class="Full\Qualified\Class3" public="false" synthetic="false" lazy="false" shared="true" abstract="false" autowired="false" autoconfigured="false" file="/path/to/file">
3+
<factory class="Full\Qualified\FactoryClass" method="get"/>
4+
</definition>

src/Symfony/Component/Asset/VersionStrategy/StaticVersionStrategy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function applyVersion(string $path)
4646
{
4747
$versionized = sprintf($this->format, ltrim($path, '/'), $this->getVersion($path));
4848

49-
if ($path && '/' == $path[0]) {
49+
if ($path && '/' === $path[0]) {
5050
return '/'.$versionized;
5151
}
5252

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function reverseTransform($value)
121121
$outputTz = new \DateTimeZone($this->outputTimezone);
122122
$dateTime = \DateTime::createFromFormat($this->parseFormat, $value, $outputTz);
123123

124-
$lastErrors = \DateTime::getLastErrors();
124+
$lastErrors = \DateTime::getLastErrors() ?: ['error_count' => 0, 'warning_count' => 0];
125125

126126
if (0 < $lastErrors['warning_count'] || 0 < $lastErrors['error_count']) {
127127
throw new TransformationFailedException(implode(', ', array_merge(array_values($lastErrors['warnings']), array_values($lastErrors['errors']))));

src/Symfony/Component/HttpFoundation/Response.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ public function send()
399399
litespeed_finish_request();
400400
} elseif (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true)) {
401401
static::closeOutputBuffers(0, true);
402+
flush();
402403
}
403404

404405
return $this;
@@ -1245,7 +1246,6 @@ public static function closeOutputBuffers(int $targetLevel, bool $flush): void
12451246
while ($level-- > $targetLevel && ($s = $status[$level]) && (!isset($s['del']) ? !isset($s['flags']) || ($s['flags'] & $flags) === $flags : $s['del'])) {
12461247
if (< D7AE span class=pl-c1>$flush) {
12471248
ob_end_flush();
1248-
flush();
12491249
} else {
12501250
ob_end_clean();
12511251
}

src/Symfony/Component/HttpKernel/Profiler/FileProfilerStorage.php

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,7 @@ public function purge()
115115
*/
116116
public function read(string $token): ?Profile
117117
{
118-
if (!$token || !file_exists($file = $this->getFilename($token))) {
119-
return null;
120-
}
121-
122-
if (\function_exists('gzcompress')) {
123-
$file = 'compress.zlib://'.$file;
124-
}
125-
126-
if (!$data = unserialize(file_get_contents($file))) {
127-
return null;
128-
}
129-
130-
return $this->createProfileFromData($token, $data);
118+
return $this->doRead($token);
131119
}
132120

133121
/**
@@ -169,14 +157,13 @@ public function write(Profile $profile): bool
169157
'status_code' => $profile->getStatusCode(),
170158
];
171159

172-
$context = stream_context_create();
160+
$data = serialize($data);
173161

174-
if (\function_exists('gzcompress')) {
175-
$file = 'compress.zlib://'.$file;
176-
stream_context_set_option($context, 'zlib', 'level', 3);
162+
if (\function_exists('gzencode')) {
163+
$data = gzencode($data, 3);
177164
}
178165

179-
if (false === file_put_contents($file, serialize($data), 0, $context)) {
166+
if (false === file_put_contents($file, $data, \LOCK_EX)) {
180167
return false;
181168
}
182169

@@ -291,21 +278,34 @@ protected function createProfileFromData(string $token, array $data, Profile $pa
291278
}
292279

293280
foreach ($data['children'] as $token) {
294-
if (!$token || !file_exists($file = $this->getFilename($token))) {
295-
continue;
281+
if (null !== $childProfile = $this->doRead($token, $profile)) {
282+
$profile->addChild($childProfile);
296283
}
284+
}
297285

298-
if (\function_exists('gzcompress')) {
299-
$file = 'compress.zlib://'.$file;
300-
}
286+
return $profile;
287+
}
301288

302-
if (!$childData = unserialize(file_get_contents($file))) {
303-
continue;
304-
}
289+
private function doRead($token, Profile $profile = null): ?Profile
290+
{
291+
if (!$token || !file_exists($file = $this->getFilename($token))) {
292+
return null;
293+
}
294+
295+
$h = fopen($file, 'r');
296+
flock($h, \LOCK_SH);
297+
$data = stream_get_contents($h);
298+
flock($h, \LOCK_UN);
299+
fclose($h);
305300

306-
$profile->addChild($this->createProfileFromData($token, $childData, $profile));
301+
if (\function_exists('gzdecode')) {
302+
$data = @gzdecode($data) ?: $data;
307303
}
308304

309-
return $profile;
305+
if (!$data = unserialize($data)) {
306+
return null;
307+
}
308+
309+
return $this->createProfileFromData($token, $data, $profile);
310310
}
311311
}

0 commit comments

Comments
 (0)
0