Skip to content

Commit 6d5617d

Browse files
committed
Merge branch '5.1' into master
* 5.1: fix merge [Cache] fix previous PR add mising sr (latn & cyrl) translations [Cache] fix ProxyAdapter not persisting items with infinite expiration [HttpClient] fail properly when the server replies with HTTP/0.9 Fix CS [Cache] Limit cache version character range [Mailer] Fixed Mailgun API bridge JsonException when API response is not applicaton/json [String] improve fix fix tests [DI] dump OS-indepent paths in the compiled container [DI] dump OS-indepent paths in the preload file Run postgres setup trigger in transaction allow consumers to mock all methods
2 parents dafcc58 + f5b08da commit 6d5617d

File tree

19 files changed

+201
-29
lines changed

19 files changed

+201
-29
lines changed

src/Symfony/Bundle/FrameworkBundle/Tests/Command/CacheClearCommand/CacheClearCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,6 @@ public function testCacheIsFreshAfterCacheClearedWithWarmup()
8484
$containerFile = str_replace('tes_'.\DIRECTORY_SEPARATOR, 'test'.\DIRECTORY_SEPARATOR, $containerRef->getFileName());
8585
$this->assertMatchesRegularExpression(sprintf('/\'kernel.container_class\'\s*=>\s*\'%s\'/', $containerClass), file_get_contents($containerFile), 'kernel.container_class is properly set on the dumped container');
8686

87-
$this->assertFileEquals(__DIR__.'/Fixture/preload.php.expected', __DIR__.'/Fixture/preload.php');
87+
$this->assertFileEquals(__DIR__.'/Fixture/preload.php.expected', __DIR__.'/Fixture/.preload.php');
8888
}
8989
}

src/Symfony/Component/Cache/Adapter/ProxyAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static function (CacheItemInterface $innerItem, array $item) {
8888
$item["\0*\0value"] = ["\x9D".pack('VN', (int) (0.1 + $metadata[self::METADATA_EXPIRY] - self::METADATA_EXPIRY_OFFSET), $metadata[self::METADATA_CTIME])."\x5F" => $item["\0*\0value"]];
8989
}
9090
$innerItem->set($item["\0*\0value"]);
91-
$innerItem->expiresAt(null !== $item["\0*\0expiry"] ? \DateTime::createFromFormat('U.u', sprintf('%.6f', $item["\0*\0expiry"])) : null);
91+
$innerItem->expiresAt(null !== $item["\0*\0expiry"] ? \DateTime::createFromFormat('U.u', sprintf('%.6f', 0 === $item["\0*\0expiry"] ? \PHP_INT_MAX : $item["\0*\0expiry"])) : null);
9292
},
9393
null,
9494
CacheItem::class

src/Symfony/Component/Cache/Tests/Adapter/TagAwareAndProxyAdapterIntegrationTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,29 @@ public function testIntegrationUsingProxiedAdapter(CacheItemPoolInterface $proxi
2424
$cache->save($item);
2525

2626
$this->assertSame('bar', $cache->getItem('foo')->get());
27+
28+
$cache->invalidateTags(['tag2']);
29+
30+
$this->assertFalse($cache->getItem('foo')->isHit());
31+
}
32+
33+
public function testIntegrationUsingProxiedAdapterForTagsPool()
34+
{
35+
$arrayAdapter = new ArrayAdapter();
36+
$cache = new TagAwareAdapter($arrayAdapter, new ProxyAdapter($arrayAdapter));
37+
38+
$item = $cache->getItem('foo');
39+
$item->expiresAfter(600);
40+
$item->tag(['baz']);
41+
$item->set('bar');
42+
$cache->save($item);
43+
44+
$this->assertSame('bar', $cache->getItem('foo')->get());
45+
$this->assertTrue($cache->getItem('foo')->isHit());
46+
47+
$cache->invalidateTags(['baz']);
48+
49+
$this->assertFalse($cache->getItem('foo')->isHit());
2750
}
2851

2952
public function dataProvider(): array

src/Symfony/Component/Cache/Traits/AbstractAdapterTrait.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public function clear(string $prefix = '')
128128
}
129129
}
130130
$namespaceToClear = $this->namespace.$namespaceVersionToClear;
131-
$namespaceVersion = substr_replace(base64_encode(pack('V', mt_rand())), static::NS_SEPARATOR, 5);
131+
$namespaceVersion = strtr(substr_replace(base64_encode(pack('V', mt_rand())), static::NS_SEPARATOR, 5), '/', '_');
132132
try {
133133
$cleared = $this->doSave([static::NS_SEPARATOR.$this->namespace => $namespaceVersion], 0);
134134
} catch (\Exception $e) {
@@ -340,7 +340,7 @@ private function generateItems(iterable $items, array &$keys): iterable
340340
try {
341341
foreach ($items as $id => $value) {
342342
if (!isset($keys[$id])) {
343-
$id = key($keys);
343+
throw new InvalidArgumentException(sprintf('Could not match value id "%s" to keys "%s".', $id, implode('", "', $keys)));
344344
}
345345
$key = $keys[$id];
346346
unset($keys[$id]);
@@ -365,7 +365,7 @@ private function getId($key)
365365
$this->namespaceVersion = $v;
366366
}
367367
if ('1'.static::NS_SEPARATOR === $this->namespaceVersion) {
368-
$this->namespaceVersion = substr_replace(base64_encode(pack('V', time())), static::NS_SEPARATOR, 5);
368+
$this->namespaceVersion = strtr(substr_replace(base64_encode(pack('V', time())), static::NS_SEPARATOR, 5), '/', '_');
369369
$this->doSave([static::NS_SEPARATOR.$this->namespace => $this->namespaceVersion], 0);
370370
}
371371
} catch (\Exception $e) {

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2056,7 +2056,15 @@ private function export($value)
20562056
$suffix = $matches[0][1] + \strlen($matches[0][0]);
20572057
$matches[0][1] += \strlen($matches[1][0]);
20582058
$prefix = $matches[0][1] ? $this->doExport(substr($value, 0, $matches[0][1]), true).'.' : '';
2059-
$suffix = isset($value[$suffix]) ? '.'.$this->doExport(substr($value, $suffix), true) : '';
2059+
2060+
if ('\\' === \DIRECTORY_SEPARATOR && isset($value[$suffix])) {
2061+
$cookie = '\\'.random_int(100000, \PHP_INT_MAX);
2062+
$suffix = '.'.$this->doExport(str_replace('\\', $cookie, substr($value, $suffix)), true);
2063+
$suffix = str_replace('\\'.$cookie, "'.\\DIRECTORY_SEPARATOR.'", $suffix);
2064+
} else {
2065+
$suffix = isset($value[$suffix]) ? '.'.$this->doExport(substr($value, $suffix), true) : '';
2066+
}
2067+
20602068
$dirname = $this->asFiles ? '$this->containerDir' : '__DIR__';
20612069
$offset = 2 + $this->targetDirMaxMatches - \count($matches);
20622070

src/Symfony/Component/DependencyInjection/Dumper/Preloader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static function append(string $file, array $list): void
2727

2828
foreach ($list as $item) {
2929
if (0 === strpos($item, $cacheDir)) {
30-
file_put_contents($file, sprintf("require_once __DIR__.%s;\n", var_export(substr($item, \strlen($cacheDir)), true)), \FILE_APPEND);
30+
file_put_contents($file, sprintf("require_once __DIR__.%s;\n", var_export(strtr(substr($item, \strlen($cacheDir)), \DIRECTORY_SEPARATOR, '/'), true)), \FILE_APPEND);
3131
continue;
3232
}
3333

src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public function testDumpAsFiles()
239239
$dumper = new PhpDumper($container);
240240
$dump = print_r($dumper->dump(['as_files' => true, 'file' => __DIR__, 'hot_path_tag' => 'hot', 'inline_factories_parameter' => false, 'inline_class_loader_parameter' => false]), true);
241241
if ('\\' === \DIRECTORY_SEPARATOR) {
242-
$dump = str_replace('\\\\Fixtures\\\\includes\\\\foo.php', '/Fixtures/includes/foo.php', $dump);
242+
$dump = str_replace("'.\\DIRECTORY_SEPARATOR.'", '/', $dump);
243243
}
244244
$this->assertStringMatchesFormatFile(self::$fixturesPath.'/php/services9_as_files.txt', $dump);
245245
}
@@ -266,7 +266,7 @@ public function testDumpAsFilesWithFactoriesInlined()
266266
$dump = print_r($dumper->dump(['as_files' => true, 'file' => __DIR__, 'hot_path_tag' => 'hot', 'build_time' => 1563381341]), true);
267267

268268
if ('\\' === \DIRECTORY_SEPARATOR) {
269-
$dump = str_replace('\\\\Fixtures\\\\includes\\\\', '/Fixtures/includes/', $dump);
269+
$dump = str_replace("'.\\DIRECTORY_SEPARATOR.'", '/', $dump);
270270
}
271271
$this->assertStringMatchesFormatFile(self::$fixturesPath.'/php/services9_inlined_factories.txt', $dump);
272272
}
@@ -292,7 +292,7 @@ public function testDumpAsFilesWithLazyFactoriesInlined()
292292
$dump = print_r($dumper->dump(['as_files' => true, 'file' => __DIR__, 'hot_path_tag' => 'hot', 'build_time' => 1563381341]), true);
293293

294294
if ('\\' === \DIRECTORY_SEPARATOR) {
295-
$dump = str_replace('\\\\Fixtures\\\\includes\\\\', '/Fixtures/includes/', $dump);
295+
$dump = str_replace("'.\\DIRECTORY_SEPARATOR.'", '/', $dump);
296296
}
297297
$this->assertStringMatchesFormatFile(self::$fixturesPath.'/php/services9_lazy_inlined_factories.txt', $dump);
298298
}
@@ -310,7 +310,7 @@ public function testNonSharedLazyDumpAsFiles()
310310
$dump = print_r($dumper->dump(['as_files' => true, 'file' => __DIR__, 'inline_factories_parameter' => false, 'inline_class_loader_parameter' => false]), true);
311311

312312
if ('\\' === \DIRECTORY_SEPARATOR) {
313-
$dump = str_replace('\\\\Fixtures\\\\includes\\\\foo_lazy.php', '/Fixtures/includes/foo_lazy.php', $dump);
313+
$dump = str_replace("'.\\DIRECTORY_SEPARATOR.'", '/', $dump);
314314
}
315315
$this->assertStringMatchesFormatFile(self::$fixturesPath.'/php/services_non_shared_lazy_as_files.txt', $dump);
316316
}
@@ -981,7 +981,7 @@ public function testArrayParameters()
981981

982982
$dumper = new PhpDumper($container);
983983

984-
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services_array_params.php', str_replace('\\\\Dumper', '/Dumper', $dumper->dump(['file' => self::$fixturesPath.'/php/services_array_params.php', 'inline_factories_parameter' => false, 'inline_class_loader_parameter' => false])));
984+
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services_array_params.php', str_replace("'.\\DIRECTORY_SEPARATOR.'", '/', $dumper->dump(['file' => self::$fixturesPath.'/php/services_array_params.php', 'inline_factories_parameter' => false, 'inline_class_loader_parameter' => false])));
985985
}
986986

987987
public function testExpressionReferencingPrivateService()
@@ -1142,7 +1142,7 @@ public function testHotPathOptimizations()
11421142

11431143
$dump = $dumper->dump(['hot_path_tag' => 'container.hot_path', 'inline_class_loader_parameter' => 'inline_requires', 'file' => self::$fixturesPath.'/php/services_inline_requires.php']);
11441144
if ('\\' === \DIRECTORY_SEPARATOR) {
1145-
$dump = str_replace("'\\\\includes\\\\HotPath\\\\", "'/includes/HotPath/", $dump);
1145+
$dump = str_replace("'.\\DIRECTORY_SEPARATOR.'", '/', $dump);
11461146
}
11471147

11481148
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services_inline_requires.php', $dump);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ private function round($number)
237237
{
238238
if (null !== $this->scale && null !== $this->roundingMode) {
239239
// shift number to maintain the correct scale during rounding
240-
$roundingCoef = pow(10, $this->scale);
240+
$roundingCoef = 10 ** $this->scale;
241241
// string representation to avoid rounding errors, similar to bcmul()
242242
$number = (string) ($number * $roundingCoef);
243243

src/Symfony/Component/HttpClient/Response/CurlResponse.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,19 @@ public function __construct(CurlClientState $multi, $ch, array $options = null,
145145
}
146146

147147
curl_setopt($ch, \CURLOPT_WRITEFUNCTION, static function ($ch, string $data) use ($multi, $id): int {
148+
if ('H' === (curl_getinfo($ch, \CURLINFO_PRIVATE)[0] ?? null)) {
149+
$multi->handlesActivity[$id][] = null;
150+
$multi->handlesActivity[$id][] = new TransportException(sprintf('Unsupported protocol for "%s"', curl_getinfo($ch, \CURLINFO_EFFECTIVE_URL)));
151+
152+
return 0;
153+
}
154+
155+
curl_setopt($ch, \CURLOPT_WRITEFUNCTION, static function ($ch, string $data) use ($multi, $id): int {
156+
$multi->handlesActivity[$id][] = $data;
157+
158+
return \strlen($data);
159+
});
160+
148161
$multi->handlesActivity[$id][] = $data;
149162

150163
return \strlen($data);

src/Symfony/Component/HttpClient/Response/TransportResponseTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ private static function addResponseHeaders(array $responseHeaders, array &$info,
116116
$debug .= "< \r\n";
117117

118118
if (!$info['http_code']) {
119-
throw new TransportException('Invalid or missing HTTP status line.');
119+
throw new TransportException(sprintf('Invalid or missing HTTP status line for "%s".', implode('', $info['url'])));
120120
}
121121
}
122122

@@ -181,7 +181,7 @@ public static function stream(iterable $responses, float $timeout = null): \Gene
181181

182182
if (\is_string($chunk = array_shift($multi->handlesActivity[$j]))) {
183183
if (null !== $response->inflate && false === $chunk = @inflate_add($response->inflate, $chunk)) {
184-
$multi->handlesActivity[$j] = [null, new TransportException('Error while processing content unencoding.')];
184+
$multi->handlesActivity[$j] = [null, new TransportException(sprintf('Error while processing content unencoding for "%s".', $response->getInfo('url')))];
185185
continue;
186186
}
187187

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy