Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit df8a505

Browse filesBrowse files
committed
Add a class option
1 parent 10ea36a commit df8a505
Copy full SHA for df8a505

File tree

4 files changed

+18
-8
lines changed
Filter options

4 files changed

+18
-8
lines changed

‎src/Symfony/Component/Dsn/ConnectionFactory.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Dsn/ConnectionFactory.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
*/
2323
class ConnectionFactory
2424
{
25-
const TYPE_REDIS = 1;
26-
const TYPE_MEMCACHED = 2;
25+
const TYPE_REDIS = 'redis';
26+
const TYPE_MEMCACHED = 'memcached';
2727

2828
/**
2929
* @param string $dsn
3030
*
31-
* @return int
31+
* @return string
3232
*/
3333
public static function getType($dsn)
3434
{

‎src/Symfony/Component/Dsn/Exception/ExceptionInterface.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Dsn/Exception/ExceptionInterface.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Symfony\Component\Dsn\Exception;
1313

1414
/**
15-
* Interface for exceptions.
15+
* Base ExceptionInterface for the Dsn Component.
1616
*
1717
* @author Jérémy Derussé <jeremy@derusse.com>
1818
*/

‎src/Symfony/Component/Dsn/Factory/MemcachedConnectionFactory.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Dsn/Factory/MemcachedConnectionFactory.php
+14-3Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
class MemcachedConnectionFactory
2222
{
2323
private static $defaultClientOptions = array(
24+
'class' => null,
2425
'persistent_id' => null,
2526
'username' => null,
2627
'password' => null,
@@ -44,7 +45,7 @@ class MemcachedConnectionFactory
4445
* @param string|string[] A DSN, or an array of DSNs
4546
* @param array An array of options
4647
*
47-
* @return \Memcached
48+
* @return \Memcached According to the "class" option
4849
*
4950
* @throws \ErrorException When invalid options or servers are provided
5051
*/
@@ -53,12 +54,22 @@ public static function createConnection($dsns, array $options = array())
5354
set_error_handler(function ($type, $msg, $file, $line) { throw new \ErrorException($msg, 0, $type, $file, $line); });
5455
try {
5556
$options += static::$defaultClientOptions;
56-
$client = new \Memcached($options['persistent_id']);
57+
58+
$class = null === $options['class'] ? \Memcached::class : $options['class'];
59+
unset($options['class']);
60+
if (is_a($class, \Memcached::class, true)) {
61+
$client = new \Memcached($options['persistent_id']);
62+
} elseif (class_exists($class, false)) {
63+
throw new InvalidArgumentException(sprintf('"%s" is not a subclass of "Memcached"', $class));
64+
} else {
65+
throw new InvalidArgumentException(sprintf('Class "%s" does not exist', $class));
66+
}
67+
5768
$username = $options['username'];
5869
$password = $options['password'];
5970

6071
// parse any DSN in $dsns
61-
$servers=[];
72+
$servers = array();
6273
foreach ((array) $dsns as $dsn) {
6374
if (0 !== strpos($dsn, 'memcached://')) {
6475
throw new InvalidArgumentException(sprintf('Invalid Memcached DSN: %s does not start with "memcached://"', $dsn));

‎src/Symfony/Component/Dsn/Tests/Factory/MemcachedConnectionFactoryTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Dsn/Tests/Factory/MemcachedConnectionFactoryTest.php
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ public function testServersSetting($dsn, $host, $port)
7777
$f = function ($s) { return array('host' => $s['host'], 'port' => $s['port']); };
7878
$this->assertSame(array($expect), array_map($f, $client1->getServerList()));
7979
$this->assertSame(array($expect), array_map($f, $client2->getServerList()));
80-
$this->assertSame(array($expect), array_map($f, $client3->getServerList()));
8180
}
8281

8382
public function provideServersSetting()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.