Skip to content

Commit 91bff21

Browse files
committed
explicitly cast boolean SSL stream options
1 parent 8306a88 commit 91bff21

File tree

1 file changed

+41
-24
lines changed

1 file changed

+41
-24
lines changed

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

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,22 @@ public static function createConnection(string $dsn, array $options = [])
250250
$extra = [
251251
'stream' => $params['ssl'] ?? null,
252252
];
253+
$booleanStreamOptions = [
254+
'allow_self_signed',
255+
'capture_peer_cert',
256+
'capture_peer_cert_chain',
257+
'disable_compression',
258+
'SNI_enabled',
259+
'verify_peer',
260+
'verify_peer_name',
261+
];
262+
263+
foreach ($extra['stream'] ?? [] as $streamOption => $value) {
264+
if (\in_array($streamOption, $booleanStreamOptions, true) && \is_string($value)) {
265+
$extra['stream'][$streamOption] = filter_var($value, \FILTER_VALIDATE_BOOL);
266+
}
267+
}
268+
253269
if (isset($params['auth'])) {
254270
$extra['auth'] = $params['auth'];
255271
}
@@ -291,9 +307,14 @@ public static function createConnection(string $dsn, array $options = [])
291307
} elseif (is_a($class, \RedisArray::class, true)) {
292308
foreach ($hosts as $i => $host) {
293309
switch ($host['scheme']) {
294-
case 'tcp': $hosts[$i] = $host['host'].':'.$host['port']; break;
295-
case 'tls': $hosts[$i] = 'tls://'.$host['host'].':'.$host['port']; break;
296-
default: $hosts[$i] = $host['path'];
310+
case 'tcp':
311+
$hosts[$i] = $host['host'].':'.$host['port'];
312+
break;
313+
case 'tls':
314+
$hosts[$i] = 'tls://'.$host['host'].':'.$host['port'];
315+
break;
316+
default:
317+
$hosts[$i] = $host['path'];
297318
}
298319
}
299320
$params['lazy_connect'] = $params['lazy'] ?? true;
@@ -312,9 +333,14 @@ public static function createConnection(string $dsn, array $options = [])
312333
$initializer = static function () use ($class, $params, $hosts) {
313334
foreach ($hosts as $i => $host) {
314335
switch ($host['scheme']) {
315-
case 'tcp': $hosts[$i] = $host['host'].':'.$host['port']; break;
316-
case 'tls': $hosts[$i] = 'tls://'.$host['host'].':'.$host['port']; break;
317-
default: $hosts[$i] = $host['path'];
336+
case 'tcp':
337+
$hosts[$i] = $host['host'].':'.$host['port'];
338+
break;
339+
case 'tls':
340+
$hosts[$i] = 'tls://'.$host['host'].':'.$host['port'];
341+
break;
342+
default:
343+
$hosts[$i] = $host['path'];
318344
}
319345
}
320346

@@ -328,9 +354,15 @@ public static function createConnection(string $dsn, array $options = [])
328354
$redis->setOption(\Redis::OPT_TCP_KEEPALIVE, $params['tcp_keepalive']);
329355
}
330356
switch ($params['failover']) {
331-
case 'error': $redis->setOption(\RedisCluster::OPT_SLAVE_FAILOVER, \RedisCluster::FAILOVER_ERROR); break;
332-
case 'distribute': $redis->setOption(\RedisCluster::OPT_SLAVE_FAILOVER, \RedisCluster::FAILOVER_DISTRIBUTE); break;
333-
case 'slaves': $redis->setOption(\RedisCluster::OPT_SLAVE_FAILOVER, \RedisCluster::FAILOVER_DISTRIBUTE_SLAVES); break;
357+
case 'error':
358+
$redis->setOption(\RedisCluster::OPT_SLAVE_FAILOVER, \RedisCluster::FAILOVER_ERROR);
359+
break;
360+
case 'distribute':
361+
$redis->setOption(\RedisCluster::OPT_SLAVE_FAILOVER, \RedisCluster::FAILOVER_DISTRIBUTE);
362+
break;
363+
case 'slaves':
364+
$redis->setOption(\RedisCluster::OPT_SLAVE_FAILOVER, \RedisCluster::FAILOVER_DISTRIBUTE_SLAVES);
365+
break;
334366
}
335367

336368
return $redis;
@@ -387,9 +419,6 @@ public static function createConnection(string $dsn, array $options = [])
387419
return $redis;
388420
}
389421

390-
/**
391-
* {@inheritdoc}
392-
*/
393422
protected function doFetch(array $ids)
394423
{
395424
if (!$ids) {
@@ -423,17 +452,11 @@ protected function doFetch(array $ids)
423452
return $result;
424453
}
425454

426-
/**
427-
* {@inheritdoc}
428-
*/
429455
protected function doHave(string $id)
430456
{
431457
return (bool) $this->redis->exists($id);
432458
}
433459

434-
/**
435-
* {@inheritdoc}
436-
*/
437460
protected function doClear(string $namespace)
438461
{
439462
if ($this->redis instanceof \Predis\ClientInterface) {
@@ -495,9 +518,6 @@ protected function doClear(string $namespace)
495518
return $cleared;
496519
}
497520

498-
/**
499-
* {@inheritdoc}
500-
*/
501521
protected function doDelete(array $ids)
502522
{
503523
if (!$ids) {
@@ -532,9 +552,6 @@ protected function doDelete(array $ids)
532552
return true;
533553
}
534554

535-
/**
536-
* {@inheritdoc}
537-
*/
538555
protected function doSave(array $values, int $lifetime)
539556
{
540557
if (!$values = $this->marshaller->marshall($values, $failed)) {

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