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 ad501b1

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

File tree

3 files changed

+15
-5
lines changed
Filter options

3 files changed

+15
-5
lines changed

‎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.