8000 Merge branch '5.2' into 5.x · symfony/symfony@bc9e946 · GitHub
[go: up one dir, main page]

Skip to content

Commit bc9e946

Browse files
Merge branch '5.2' into 5.x
* 5.2: Move github templates at the org level [Cache] Fix Redis TLS scheme `rediss` for Redis connection In calls to mb_ functions, silently transform arg into string Switched to non-null defaults in exception constructors [Routing] fix conflict with param named class in attribute [Cache] fix setting items' metadata on commit()
2 parents 858dca4 + e98ab92 commit bc9e946

File tree

76 files changed

+381
-218
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+381
-218
lines changed

.github/CODE_OF_CONDUCT.md

Lines changed: 0 additions & 8 deletions
This file was deleted.

.github/ISSUE_TEMPLATE/1_Bug_report.md

Lines changed: 0 additions & 22 deletions
This file was deleted.

.github/ISSUE_TEMPLATE/2_Feature_request.md

Lines changed: 0 additions & 12 deletions
This file was deleted.

.github/ISSUE_TEMPLATE/3_Support_question.md

Lines changed: 0 additions & 11 deletions
This file was deleted.

.github/ISSUE_TEMPLATE/4_Documentation_issue.md

Lines changed: 0 additions & 10 deletions
This file was deleted.

.github/SECURITY.md

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/Symfony/Bundle/FrameworkBundle/Routing/DelegatingLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function load($resource, string $type = null)
6161
// - this handles the case and prevents the second fatal error
6262
// by triggering an exception beforehand.
6363

64-
throw new LoaderLoadException($resource, null, null, null, $type);
64+
throw new LoaderLoadException($resource, null, 0, null, $type);
6565
}
6666
$this->loading = true;
F438
6767

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ static function ($deferred, &$expiredIds) use ($getId, $tagPrefix, $defaultLifet
110110
}
111111

112112
$byLifetime[$ttl][$getId($key)] = $value;
113+
$item->metadata = $item->newMetadata;
113114
}
114115

115116
return $byLifetime;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ static function ($deferred) {
8383
$tagsByKey = [];
8484
foreach ($deferred as $key => $item) {
8585
$tagsByKey[$key] = $item->newMetadata[CacheItem::METADATA_TAGS] ?? [];
86+
$item->metadata = $item->newMetadata;
8687
}
8788

8889
return $tagsByKey;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use Psr\Cache\CacheItemPoolInterface;
1515
use Symfony\Component\Cache\Adapter\FilesystemTagAwareAdapter;
16-
use Symfony\Component\Cache\Tests\Traits\TagAwareTestTrait;
1716

1817
/**
1918
* @group time-sensitive

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use Psr\Cache\CacheItemPoolInterface;
1515
use Symfony\Component\Cache\Adapter\PdoAdapter;
16-
use Symfony\Component\Cache\Tests\Traits\PdoPruneableTrait;
1716

1817
/**
1918
* @group time-sensitive

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use Doctrine\DBAL\Schema\Schema;
1818
use Psr\Cache\CacheItemPoolInterface;
1919
use Symfony\Component\Cache\Adapter\PdoAdapter;
20-
use Symfony\Component\Cache\Tests\Traits\PdoPruneableTrait;
2120

2221
/**
2322
* @group time-sensitive

src/Symfony/Component/Cache/Tests/Traits/PdoPruneableTrait.php renamed to src/Symfony/Component/Cache/Tests/Adapter/PdoPruneableTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\Cache\Tests\Traits;
12+
namespace Symfony\Component\Cache\Tests\Adapter;
1313

1414
trait PdoPruneableTrait
1515
{

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use Psr\Cache\CacheItemPoolInterface;
1515
use Symfony\Component\Cache\Adapter\RedisTagAwareAdapter;
16-
use Symfony\Component\Cache\Tests\Traits\TagAwareTestTrait;
1716

1817
/**
1918
* @group integration

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use Psr\Cache\CacheItemPoolInterface;
1515
use Symfony\Component\Cache\Adapter\RedisTagAwareAdapter;
16-
use Symfony\Component\Cache\Tests\Traits\TagAwareTestTrait;
1716

1817
/**
1918
* @group integration

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

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,36 +36,46 @@ public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterfac
3636
return $adapter;
3737
}
3838

39-
/**
40-
* @dataProvider provideValidSchemes
41-
*/
42-
public function testCreateConnection(string $dsnScheme)
39+
public function testCreateConnection()
4340
{
44-
$redis = RedisAdapter::createConnection($dsnScheme.':?host[h1]&host[h2]&host[/foo:]');
41+
$redis = RedisAdapter::createConnection('redis:?host[h1]&host[h2]&host[/foo:]');
4542
$this->assertInstanceOf(\RedisArray::class, $redis);
4643
$this->assertSame(['h1:6379', 'h2:6379', '/foo'], $redis->_hosts());
4744
@$redis = null; // some versions of phpredis connect on destruct, let's silence the warning
4845

4946
$redisHost = getenv('REDIS_HOST');
5047

51-
$redis = RedisAdapter::createConnection($dsnScheme.'://'.$redisHost);
48+
$redis = RedisAdapter::createConnection('redis://'.$redisHost);
5249
$this->assertInstanceOf(\Redis::class, $redis);
5350
$this->assertTrue($redis->isConnected());
5451
$this->assertSame(0, $redis->getDbNum());
5552

56-
$redis = RedisAdapter::createConnection($dsnScheme.'://'.$redisHost.'/2');
53+
$redis = RedisAdapter::createConnection('redis://'.$redisHost.'/2');
5754
$this->assertSame(2, $redis->getDbNum());
5855

59-
$redis = RedisAdapter::createConnection($dsnScheme.'://'.$redisHost, ['timeout' => 3]);
56+
$redis = RedisAdapter::createConnection('redis://'.$redisHost, ['timeout' => 3]);
6057
$this->assertEquals(3, $redis->getTimeout());
6158

62-
$redis = RedisAdapter::createConnection($dsnScheme.'://'.$redisHost.'?timeout=4');
59+
$redis = RedisAdapter::createConnection('redis://'.$redisHost.'?timeout=4');
6360
$this->assertEquals(4, $redis->getTimeout());
6461

65-
$redis = RedisAdapter::createConnection($dsnScheme.'://'.$redisHost, ['read_timeout' => 5]);
62+
$redis = RedisAdapter::createConnection('redis://'.$redisHost, ['read_timeout' => 5]);
6663
$this->assertEquals(5, $redis->getReadTimeout());
6764
}
6865

66+
public function testCreateTlsConnection()
67+
{
68+
$redis = RedisAdapter::createConnection('rediss:?host[h1]&host[h2]&host[/foo:]');
69+
$this->assertInstanceOf(\RedisArray::class BD94 , $redis);
70+
$this->assertSame(['tls://h1:6379', 'tls://h2:6379', '/foo'], $redis->_hosts());
71+
@$redis = null; // some versions of phpredis connect on destruct, let's silence the warning
72+
73+
$redisHost = getenv('REDIS_HOST');
74+
75+
$redis = RedisAdapter::createConnection('rediss://'.$redisHost.'?lazy=1');
76+
$this->assertInstanceOf(RedisProxy::class, $redis);
77+
}
78+
6979
/**
7080
* @dataProvider provideFailedCreateConnection
7181
*/
@@ -95,14 +105,6 @@ public function testInvalidCreateConnection(string $dsn)
95105
RedisAdapter::createConnection($dsn);
96106
}
97107

98-
public function provideValidSchemes(): array
99-
{
100-
return [
101-
['redis'],
102-
['rediss'],
103-
];
104-
}
105-
106108
public function provideInvalidCreateConnection(): array
107109
{
108110
return [

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use Psr\Cache\CacheItemPoolInterface;
1515
use Symfony\Component\Cache\Adapter\RedisTagAwareAdapter;
16-
use Symfony\Component\Cache\Tests\Traits\TagAwareTestTrait;
1716
use Symfony\Component\Cache\Traits\RedisProxy;
1817

1918
/**

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use Psr\Cache\CacheItemPoolInterface;
1515
use Symfony\Component\Cache\Adapter\RedisTagAwareAdapter;
16-
use Symfony\Component\Cache\Tests\Traits\TagAwareTestTrait;
1716

1817
/**
1918
* @group integration

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use Psr\Cache\CacheItemPoolInterface;
1515
use Symfony\Component\Cache\Adapter\RedisTagAwareAdapter;
16-
use Symfony\Component\Cache\Tests\Traits\TagAwareTestTrait;
1716
use Symfony\Component\Cache\Traits\RedisClusterProxy;
1817

1918
/**

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
2020
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
2121
use Symfony\Component\Cache\Tests\Fixtures\PrunableAdapter;
22-
use Symfony\Component\Cache\Tests\Traits\TagAwareTestTrait;
2322
use Symfony\Component\Filesystem\Filesystem;
2423

2524
/**

src/Symfony/Component/Cache/Tests/Traits/TagAwareTestTrait.php renamed to src/Symfony/Component/Cache/Tests/Adapter/TagAwareTestTrait.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\Cache\Tests\Traits;
12+
namespace Symfony\Component\Cache\Tests\Adapter;
1313

1414
use Symfony\Component\Cache\CacheItem;
1515

@@ -136,7 +136,9 @@ public function testGetMetadata()
136136
$pool = $this->createCachePool();
137137

138138
$i = $pool->getItem('k');
139+
$this->assertSame([], $i->getMetadata());
139140
$pool->save($i->tag('foo'));
141+
$this->assertSame(['foo' => 'foo'], $i->getMetadata()[CacheItem::METADATA_TAGS]);
140142

141143
$i = $pool->getItem('k');
142144
$this->assertSame(['foo' => 'foo'], $i->getMetadata()[CacheItem::METADATA_TAGS]);

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

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ public static function createConnection($dsn, array $options = [])
119119

120120
$query = $hosts = [];
121121

122+
$tls = 'rediss' === $scheme;
123+
$tcpScheme = $tls ? 'tls' : 'tcp';
124+
122125
if (isset($params['query'])) {
123126
parse_str($params['query'], $query);
124127

@@ -131,9 +134,9 @@ public static function createConnection($dsn, array $options = [])
131134
parse_str($parameters, $parameters);
132135
}
133136
if (false === $i = strrpos($host, ':')) {
134-
$hosts[$host] = ['scheme' => 'tcp', 'host' => $host, 'port' => 6379] + $parameters;
137+
$hosts[$host] = ['scheme' => $tcpScheme, 'host' => $host, 'port' => 6379] + $parameters;
135138
} elseif ($port = (int) substr($host, 1 + $i)) {
136-
$hosts[$host] = ['scheme' => 'tcp', 'host' => substr($host, 0, $i), 'port' => $port] + $parameters;
139+
$hosts[$host] = ['scheme' => $tcpScheme, 'host' => substr($host, 0, $i), 'port' => $port] + $parameters;
137140
} else {
138141
$hosts[$host] = ['scheme' => 'unix', 'path' => substr($host, 0, $i)] + $parameters;
139142
}
@@ -149,7 +152,7 @@ public static function createConnection($dsn, array $options = [])
149152
}
150153

151154
if (isset($params['host'])) {
152-
array_unshift($hosts, ['scheme' => 'tcp', 'host' => $params['host'], 'port' => $params['port'] ?? 6379]);
155+
array_unshift($hosts, ['scheme' => $tcpScheme, 'host' => $params['host'], 'port' => $params['port'] ?? 6379]);
153156
} else {
154157
array_unshift($hosts, ['scheme' => 'unix', 'path' => $params['path']]);
155158
}
@@ -179,10 +182,14 @@ public static function createConnection($dsn, array $options = [])
179182
$connect = $params['persistent'] || $params['persistent_id'] ? 'pconnect' : 'connect';
180183
$redis = new $class();
181184

182-
$initializer = static function ($redis) use ($connect, $params, $dsn, $auth, $hosts) {
185+
$initializer = static function ($redis) use ($connect, $params, $dsn, $auth, $hosts, $tls) {
183186
$host = $hosts[0]['host'] ?? $hosts[0]['path'];
184187
$port = $hosts[0]['port'] ?? null;
185188

189+
if (isset($hosts[0]['host']) && $tls) {
190+
$host = 'tls://'.$host;
191+
}
192+
186193
if (isset($params['redis_sentinel'])) {
187194
$sentinel = new \RedisSentinel($host, $port, $params['timeout'], (string) $params['persistent_id'], $params['retry_interval'], $params['read_timeout']);
188195

@@ -228,7 +235,11 @@ public static function createConnection($dsn, array $options = [])
228235
}
229236
} elseif (is_a($class, \RedisArray::class, true)) {
230237
foreach ($hosts as $i => $host) {
231-
$hosts[$i] = 'tcp' === $host['scheme'] ? $host['host'].':'.$host['port'] : $host['path'];
238+
switch ($host['scheme']) {
239+
case 'tcp': $hosts[$i] = $host['host'].':'.$host['port']; break;
240+
case 'tls': $hosts[$i] = 'tls://'.$host['host'].':'.$host['port']; break;
241+
default: $hosts[$i] = $host['path'];
242+
}
232243
}
233244
$params['lazy_connect'] = $params['lazy'] ?? true;
234245
$params['connect_timeout'] = $params['timeout'];
@@ -245,7 +256,11 @@ public static function createConnection($dsn, array $options = [])
245256
} elseif (is_a($class, \RedisCluster::class, true)) {
246257
$initializer = static function () use ($class, $params, $dsn, $hosts) {
247258
foreach ($hosts as $i => $host) {
248-
$hosts[$i] = 'tcp' === $host['scheme'] ? $host['host'].':'.$host['port'] : $host['path'];
259+
switch ($host['scheme']) {
260+
case 'tcp': $hosts[$i] = $host['host'].':'.$host['port']; break;
261+
case 'tls': $hosts[$i] = 'tls://'.$host['host'].':'.$host['port']; break;
262+
default: $hosts[$i] = $host['path'];
263+
}
249264
}
250265

251266
try {

src/Symfony/Component/Config/Exception/FileLoaderImportCircularReferenceException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
class FileLoaderImportCircularReferenceException extends LoaderLoadException
2020
{
21-
public function __construct(array $resources, int $code = null, \Throwable $previous = null)
21+
public function __construct(array $resources, ?int $code = 0, \Throwable $previous = null)
2222
{
2323
$message = sprintf('Circular reference detected in "%s" ("%s" > "%s").', $this->varToString($resources[0]), implode('" > "', $resources), $resources[0]);
2424

src/Symfony/Component/Config/Loader/DelegatingLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct(LoaderResolverInterface $resolver)
3434
public function load($resource, string $type = null)
3535
{
3636
if (false === $loader = $this->resolver->resolve($resource, $type)) {
37-
throw new LoaderLoadException($resource, null, null, null, $type);
37+
throw new LoaderLoadException($resource, null, 0, null, $type);
3838
}
3939

4040
return $loader->load($resource, $type);

src/Symfony/Component/Config/Loader/FileLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ private function doImport($resource, string $type = null, bool $ignoreErrors = f
171171
throw $e;
172172
}
173173

174-
throw new LoaderLoadException($resource, $sourceResource, null, $e, $type);
174+
throw new LoaderLoadException($resource, $sourceResource, 0, $e, $type);
175175
}
176176
}
177177

src/Symfony/Component/Config/Loader/Loader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function resolve($resource, string $type = null)
7676
$loader = null === $this->resolver ? false : $this->resolver->resolve($resource, $type);
7777

7878
if (false === $loader) {
79-
throw new LoaderLoadException($resource, null, null, null, $type);
79+
throw new LoaderLoadException($resource, null, 0, null, $type);
8080
}
8181

8282
return $loader;

0 commit comments

Comments
 (0)
0