Merge branch '4.4' into 5.2
* 4.4: 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
This commit is contained in:
commit
e98ab925e3
8
.github/CODE_OF_CONDUCT.md
vendored
8
.github/CODE_OF_CONDUCT.md
vendored
@ -1,8 +0,0 @@
|
||||
# Code of Conduct
|
||||
|
||||
This project follows a [Code of Conduct][code_of_conduct] in order to ensure an open and welcoming environment.
|
||||
Please read the full text for understanding the accepted and unaccepted behavior.
|
||||
Please read also the [reporting guidelines][guidelines], in case you encountered or witnessed any misbehavior.
|
||||
|
||||
[code_of_conduct]: https://symfony.com/doc/current/contributing/code_of_conduct/index.html
|
||||
[guidelines]: https://symfony.com/doc/current/contributing/code_of_conduct/reporting_guidelines.html
|
22
.github/ISSUE_TEMPLATE/1_Bug_report.md
vendored
22
.github/ISSUE_TEMPLATE/1_Bug_report.md
vendored
@ -1,22 +0,0 @@
|
||||
---
|
||||
name: 🐛 Bug Report
|
||||
about: Report errors and problems
|
||||
labels: Bug
|
||||
|
||||
---
|
||||
|
||||
**Symfony version(s) affected**: x.y.z
|
||||
|
||||
**Description**
|
||||
<!-- A clear and concise description of the problem. -->
|
||||
|
||||
**How to reproduce**
|
||||
<!-- Code and/or config needed to reproduce the problem. If it's a complex bug,
|
||||
create a "bug reproducer" as explained in:
|
||||
https://symfony.com/doc/current/contributing/code/reproducer.html -->
|
||||
|
||||
**Possible Solution**
|
||||
<!--- Optional: only if you have suggestions on a fix/reason for the bug -->
|
||||
|
||||
**Additional context**
|
||||
<!-- Optional: any other context about the problem: log messages, screenshots, etc. -->
|
12
.github/ISSUE_TEMPLATE/2_Feature_request.md
vendored
12
.github/ISSUE_TEMPLATE/2_Feature_request.md
vendored
@ -1,12 +0,0 @@
|
||||
---
|
||||
name: 🚀 Feature Request
|
||||
about: RFC and ideas for new features and improvements
|
||||
|
||||
---
|
||||
|
||||
**Description**
|
||||
<!-- A clear and concise description of the new feature. -->
|
||||
|
||||
**Example**
|
||||
<!-- A simple example of the new feature in action (include PHP code, YAML config, etc.)
|
||||
If the new feature changes an existing feature, include a simple before/after comparison. -->
|
11
.github/ISSUE_TEMPLATE/3_Support_question.md
vendored
11
.github/ISSUE_TEMPLATE/3_Support_question.md
vendored
@ -1,11 +0,0 @@
|
||||
---
|
||||
name: ⛔ Support Question
|
||||
about: See https://symfony.com/support for questions about using Symfony and its components
|
||||
|
||||
---
|
||||
|
||||
We use GitHub issues only to discuss about Symfony bugs and new features. For
|
||||
this kind of questions about using Symfony or third-party bundles, please use
|
||||
any of the support alternatives shown in https://symfony.com/support
|
||||
|
||||
Thanks!
|
10
.github/ISSUE_TEMPLATE/4_Documentation_issue.md
vendored
10
.github/ISSUE_TEMPLATE/4_Documentation_issue.md
vendored
@ -1,10 +0,0 @@
|
||||
---
|
||||
name: ⛔ Documentation Issue
|
||||
about: See https://github.com/symfony/symfony-docs/issues for documentation issues
|
||||
|
||||
---
|
||||
|
||||
Symfony Documentation has its own dedicated repository. Please open your
|
||||
documentation-related issue at https://github.com/symfony/symfony-docs/issues
|
||||
|
||||
Thanks!
|
10
.github/SECURITY.md
vendored
10
.github/SECURITY.md
vendored
@ -1,10 +0,0 @@
|
||||
Security Policy
|
||||
===============
|
||||
|
||||
If you found any issues that might have security implications,
|
||||
please send a report to security[at]symfony.com
|
||||
DO NOT PUBLISH SECURITY REPORTS PUBLICLY.
|
||||
|
||||
The full [Security Policy][1] is described in the official documentation.
|
||||
|
||||
[1]: https://symfony.com/security
|
@ -36,36 +36,46 @@ class RedisAdapterTest extends AbstractRedisAdapterTest
|
||||
return $adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideValidSchemes
|
||||
*/
|
||||
public function testCreateConnection(string $dsnScheme)
|
||||
public function testCreateConnection()
|
||||
{
|
||||
$redis = RedisAdapter::createConnection($dsnScheme.':?host[h1]&host[h2]&host[/foo:]');
|
||||
$redis = RedisAdapter::createConnection('redis:?host[h1]&host[h2]&host[/foo:]');
|
||||
$this->assertInstanceOf(\RedisArray::class, $redis);
|
||||
$this->assertSame(['h1:6379', 'h2:6379', '/foo'], $redis->_hosts());
|
||||
@$redis = null; // some versions of phpredis connect on destruct, let's silence the warning
|
||||
|
||||
$redisHost = getenv('REDIS_HOST');
|
||||
|
||||
$redis = RedisAdapter::createConnection($dsnScheme.'://'.$redisHost);
|
||||
$redis = RedisAdapter::createConnection('redis://'.$redisHost);
|
||||
$this->assertInstanceOf(\Redis::class, $redis);
|
||||
$this->assertTrue($redis->isConnected());
|
||||
$this->assertSame(0, $redis->getDbNum());
|
||||
|
||||
$redis = RedisAdapter::createConnection($dsnScheme.'://'.$redisHost.'/2');
|
||||
$redis = RedisAdapter::createConnection('redis://'.$redisHost.'/2');
|
||||
$this->assertSame(2, $redis->getDbNum());
|
||||
|
||||
$redis = RedisAdapter::createConnection($dsnScheme.'://'.$redisHost, ['timeout' => 3]);
|
||||
$redis = RedisAdapter::createConnection('redis://'.$redisHost, ['timeout' => 3]);
|
||||
$this->assertEquals(3, $redis->getTimeout());
|
||||
|
||||
$redis = RedisAdapter::createConnection($dsnScheme.'://'.$redisHost.'?timeout=4');
|
||||
$redis = RedisAdapter::createConnection('redis://'.$redisHost.'?timeout=4');
|
||||
$this->assertEquals(4, $redis->getTimeout());
|
||||
|
||||
$redis = RedisAdapter::createConnection($dsnScheme.'://'.$redisHost, ['read_timeout' => 5]);
|
||||
$redis = RedisAdapter::createConnection('redis://'.$redisHost, ['read_timeout' => 5]);
|
||||
$this->assertEquals(5, $redis->getReadTimeout());
|
||||
}
|
||||
|
||||
public function testCreateTlsConnection()
|
||||
{
|
||||
$redis = RedisAdapter::createConnection('rediss:?host[h1]&host[h2]&host[/foo:]');
|
||||
$this->assertInstanceOf(\RedisArray::class, $redis);
|
||||
$this->assertSame(['tls://h1:6379', 'tls://h2:6379', '/foo'], $redis->_hosts());
|
||||
@$redis = null; // some versions of phpredis connect on destruct, let's silence the warning
|
||||
|
||||
$redisHost = getenv('REDIS_HOST');
|
||||
|
||||
$redis = RedisAdapter::createConnection('rediss://'.$redisHost.'?lazy=1');
|
||||
$this->assertInstanceOf(RedisProxy::class, $redis);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideFailedCreateConnection
|
||||
*/
|
||||
@ -95,14 +105,6 @@ class RedisAdapterTest extends AbstractRedisAdapterTest
|
||||
RedisAdapter::createConnection($dsn);
|
||||
}
|
||||
|
||||
public function provideValidSchemes(): array
|
||||
{
|
||||
return [
|
||||
['redis'],
|
||||
['rediss'],
|
||||
];
|
||||
}
|
||||
|
||||
public function provideInvalidCreateConnection(): array
|
||||
{
|
||||
return [
|
||||
|
@ -119,6 +119,9 @@ trait RedisTrait
|
||||
|
||||
$query = $hosts = [];
|
||||
|
||||
$tls = 'rediss' === $scheme;
|
||||
$tcpScheme = $tls ? 'tls' : 'tcp';
|
||||
|
||||
if (isset($params['query'])) {
|
||||
parse_str($params['query'], $query);
|
||||
|
||||
@ -131,9 +134,9 @@ trait RedisTrait
|
||||
parse_str($parameters, $parameters);
|
||||
}
|
||||
if (false === $i = strrpos($host, ':')) {
|
||||
$hosts[$host] = ['scheme' => 'tcp', 'host' => $host, 'port' => 6379] + $parameters;
|
||||
$hosts[$host] = ['scheme' => $tcpScheme, 'host' => $host, 'port' => 6379] + $parameters;
|
||||
} elseif ($port = (int) substr($host, 1 + $i)) {
|
||||
$hosts[$host] = ['scheme' => 'tcp', 'host' => substr($host, 0, $i), 'port' => $port] + $parameters;
|
||||
$hosts[$host] = ['scheme' => $tcpScheme, 'host' => substr($host, 0, $i), 'port' => $port] + $parameters;
|
||||
} else {
|
||||
$hosts[$host] = ['scheme' => 'unix', 'path' => substr($host, 0, $i)] + $parameters;
|
||||
}
|
||||
@ -149,7 +152,7 @@ trait RedisTrait
|
||||
}
|
||||
|
||||
if (isset($params['host'])) {
|
||||
array_unshift($hosts, ['scheme' => 'tcp', 'host' => $params['host'], 'port' => $params['port'] ?? 6379]);
|
||||
array_unshift($hosts, ['scheme' => $tcpScheme, 'host' => $params['host'], 'port' => $params['port'] ?? 6379]);
|
||||
} else {
|
||||
array_unshift($hosts, ['scheme' => 'unix', 'path' => $params['path']]);
|
||||
}
|
||||
@ -175,9 +178,16 @@ trait RedisTrait
|
||||
$connect = $params['persistent'] || $params['persistent_id'] ? 'pconnect' : 'connect';
|
||||
$redis = new $class();
|
||||
|
||||
$initializer = static function ($redis) use ($connect, $params, $dsn, $auth, $hosts) {
|
||||
$initializer = static function ($redis) use ($connect, $params, $dsn, $auth, $hosts, $tls) {
|
||||
$host = $hosts[0]['host'] ?? $hosts[0]['path'];
|
||||
$port = $hosts[0]['port'] ?? null;
|
||||
|
||||
if (isset($hosts[0]['host']) && $tls) {
|
||||
$host = 'tls://'.$host;
|
||||
}
|
||||
|
||||
try {
|
||||
@$redis->{$connect}($hosts[0]['host'] ?? $hosts[0]['path'], $hosts[0]['port'] ?? null, $params['timeout'], (string) $params['persistent_id'], $params['retry_interval'], $params['read_timeout']);
|
||||
@$redis->{$connect}($host, $port, $params['timeout'], (string) $params['persistent_id'], $params['retry_interval'], $params['read_timeout']);
|
||||
|
||||
set_error_handler(function ($type, $msg) use (&$error) { $error = $msg; });
|
||||
$isConnected = $redis->isConnected();
|
||||
@ -211,7 +221,11 @@ trait RedisTrait
|
||||
}
|
||||
} elseif (is_a($class, \RedisArray::class, true)) {
|
||||
foreach ($hosts as $i => $host) {
|
||||
$hosts[$i] = 'tcp' === $host['scheme'] ? $host['host'].':'.$host['port'] : $host['path'];
|
||||
switch ($host['scheme']) {
|
||||
case 'tcp': $hosts[$i] = $host['host'].':'.$host['port']; break;
|
||||
case 'tls': $hosts[$i] = 'tls://'.$host['host'].':'.$host['port']; break;
|
||||
default: $hosts[$i] = $host['path'];
|
||||
}
|
||||
}
|
||||
$params['lazy_connect'] = $params['lazy'] ?? true;
|
||||
$params['connect_timeout'] = $params['timeout'];
|
||||
@ -228,7 +242,11 @@ trait RedisTrait
|
||||
} elseif (is_a($class, \RedisCluster::class, true)) {
|
||||
$initializer = static function () use ($class, $params, $dsn, $hosts) {
|
||||
foreach ($hosts as $i => $host) {
|
||||
$hosts[$i] = 'tcp' === $host['scheme'] ? $host['host'].':'.$host['port'] : $host['path'];
|
||||
switch ($host['scheme']) {
|
||||
case 'tcp': $hosts[$i] = $host['host'].':'.$host['port']; break;
|
||||
case 'tls': $hosts[$i] = 'tls://'.$host['host'].':'.$host['port']; break;
|
||||
default: $hosts[$i] = $host['path'];
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -45,6 +45,8 @@ abstract class Helper implements HelperInterface
|
||||
*/
|
||||
public static function strlen(?string $string)
|
||||
{
|
||||
$string = (string) $string;
|
||||
|
||||
if (false === $encoding = mb_detect_encoding($string, null, true)) {
|
||||
return \strlen($string);
|
||||
}
|
||||
@ -59,6 +61,8 @@ abstract class Helper implements HelperInterface
|
||||
*/
|
||||
public static function substr(string $string, int $from, int $length = null)
|
||||
{
|
||||
$string = (string) $string;
|
||||
|
||||
if (false === $encoding = mb_detect_encoding($string, null, true)) {
|
||||
return substr($string, $from, $length);
|
||||
}
|
||||
|
Reference in New Issue
Block a user