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

[Dsn] New component #24267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions 7 UPGRADE-3.4.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
UPGRADE FROM 3.3 to 3.4
=======================

Cache
-----

* The `AbstractAdapter::createConnection()`, `RedisTrait::createConnection()`
and `MemcachedTrait::createConnection()` methods have been deprecated and
will be removed in 4.0. Use the Dsn component instead.

DependencyInjection
-------------------

Expand Down
7 changes: 7 additions & 0 deletions 7 UPGRADE-4.0.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
UPGRADE FROM 3.x to 4.0
=======================

Cache
-----

* The `AbstractAdapter::createConnection()`, `RedisTrait::createConnection()`
and `MemcachedTrait::createConnection()` methods have been removed. Use the
Dsn component instead.

ClassLoader
-----------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\Dsn\ConnectionFactory;

/**
* @author Nicolas Grekas <p@tchwork.com>
Expand Down Expand Up @@ -133,7 +135,7 @@ public static function getServiceProvider(ContainerBuilder $container, $name)
if (!$container->hasDefinition($name = 'cache_connection.'.ContainerBuilder::hash($dsn))) {
$definition = new Definition(AbstractAdapter::class);
$definition->setPublic(false);
$definition->setFactory(array(AbstractAdapter::class, 'createConnection'));
$definition->setFactory(array(ConnectionFactory::class, 'createConnection'));
$definition->setArguments(array($dsn));
$container->setDefinition($name, $definition);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ServiceSubscriberInterface;
use Symfony\Component\Dsn\ConnectionFactory;
use Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
Expand Down Expand Up @@ -1706,7 +1707,7 @@ private function registerLockConfiguration(array $config, ContainerBuilder $cont
if (!$container->hasDefinition($connectionDefinitionId = $container->hash($storeDsn))) {
$connectionDefinition = new Definition(\stdClass::class);
$connectionDefinition->setPublic(false);
$connectionDefinition->setFactory(array(StoreFactory::class, 'createConnection'));
$connectionDefinition->setFactory(array(ConnectionFactory::class, 'createConnection'));
$connectionDefinition->setArguments(array($storeDsn));
$container->setDefinition($connectionDefinitionId, $connectionDefinition);
}
Expand Down
1 change: 1 addition & 0 deletions 1 src/Symfony/Bundle/FrameworkBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"symfony/browser-kit": "~2.8|~3.0|~4.0",
"symfony/console": "~3.4|~4.0",
"symfony/css-selector": "~2.8|~3.0|~4.0",
"symfony/dsn": "~3.4",
"symfony/dom-crawler": "~2.8|~3.0|~4.0",
"symfony/polyfill-intl-icu": "~1.0",
"symfony/security": "~2.8|~3.0|~4.0",
Expand Down
23 changes: 16 additions & 7 deletions 23 src/Symfony/Component/Cache/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
use Symfony\Component\Cache\Exception\InvalidArgumentException;
use Symfony\Component\Cache\ResettableInterface;
use Symfony\Component\Cache\Traits\AbstractTrait;
use Symfony\Component\Dsn\ConnectionFactory;
use Symfony\Component\Dsn\Exception\InvalidArgumentException as DsnInvalidArgumentException;
use Symfony\Component\Dsn\Factory\MemcachedFactory;
use Symfony\Component\Dsn\Factory\RedisFactory;

/**
* @author Nicolas Grekas <p@tchwork.com>
Expand Down Expand Up @@ -128,14 +132,19 @@ public static function createSystemCache($namespace, $defaultLifetime, $version,

public static function createConnection($dsn, array $options = array())
{
if (!is_string($dsn)) {
throw new InvalidArgumentException(sprintf('The %s() method expect argument #1 to be string, %s given.', __METHOD__, gettype($dsn)));
}
if (0 === strpos($dsn, 'redis://')) {
return RedisAdapter::createConnection($dsn, $options);
@trigger_error(sprintf('The %s() method is deprecated since version 3.4 and will be removed in 4.0. Use the ConnectionFactory::create() method from Dsn component instead.', __METHOD__), E_USER_DEPRECATED);

try {
$type = ConnectionFactory::getType($dsn);
} catch (DsnInvalidArgumentException $e) {
throw new InvalidArgumentException($e->getMessage(), 0, $e);
}
if (0 === strpos($dsn, 'memcached://')) {
return MemcachedAdapter::createConnection($dsn, $options);

switch ($type) {
case ConnectionFactory::TYPE_MEMCACHED:
return MemcachedFactory::create($dsn, $options);
case ConnectionFactory::TYPE_REDIS:
return RedisFactory::create($dsn, $options);
}

throw new InvalidArgumentException(sprintf('Unsupported DSN: %s.', $dsn));
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/Cache/Adapter/MemcachedAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class MemcachedAdapter extends AbstractAdapter
* Using a MemcachedAdapter with a TagAwareAdapter for storing tags is discouraged.
* Using a RedisAdapter is recommended instead. If you cannot do otherwise, be aware that:
* - the Memcached::OPT_BINARY_PROTOCOL must be enabled
* (that's the default when using MemcachedAdapter::createConnection());
* (that's the default when using MemcachedFactory::create());
* - tags eviction by Memcached's LRU algorithm will break by-tags invalidation;
* your Memcached memory should be large enough to never trigger LRU.
*
Expand Down
2 changes: 2 additions & 0 deletions 2 src/Symfony/Component/Cache/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ CHANGELOG
* added prune logic to FilesystemTrait, PhpFilesTrait, PdoTrait, TagAwareAdapter and ChainTrait
* now FilesystemAdapter, PhpFilesAdapter, FilesystemCache, PhpFilesCache, PdoAdapter, PdoCache, ChainAdapter, and
ChainCache implement PruneableInterface and support manual stale cache pruning
* deprecated `AbstractAdapter::createConnection()`, `RedisTrait::createConnection()` and
`MemcachedTrait::createConnection()`

3.3.0
-----
Expand Down
35 changes: 18 additions & 17 deletions 35 src/Symfony/Component/Cache/Tests/Adapter/MemcachedAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

namespace Symfony\Component\Cache\Tests\Adapter;

use Symfony\Component\Cache\Adapter\AbstractAdapter;
use Symfony\Component\Cache\Adapter\MemcachedAdapter;
use Symfony\Component\Dsn\Factory\MemcachedFactory;

class MemcachedAdapterTest extends AdapterTestCase
{
Expand All @@ -28,7 +28,7 @@ public static function setupBeforeClass()
if (!MemcachedAdapter::isSupported()) {
self::markTestSkipped('Extension memcached >=2.2.0 required.');
}
self::$client = AbstractAdapter::createConnection('memcached://'.getenv('MEMCACHED_HOST'), array('binary_protocol' => false));
self::$client = MemcachedFactory::create('memcached://'.getenv('MEMCACHED_HOST'), array('binary_protocol' => false));
self::$client->get('foo');
$code = self::$client->getResultCode();

Expand All @@ -39,29 +39,24 @@ public static function setupBeforeClass()

public function createCachePool($defaultLifetime = 0)
{
$client = $defaultLifetime ? AbstractAdapter::createConnection('memcached://'.getenv('MEMCACHED_HOST')) : self::$client;
$client = $defaultLifetime ? MemcachedFactory::create('memcached://'.getenv('MEMCACHED_HOST')) : self::$client;

return new MemcachedAdapter($client, str_replace('\\', '.', __CLASS__), $defaultLifetime);
}

public function testOptions()
/**
* @group legacy
* @expectedDeprecation The %s() method is deprecated since version 3.4 and will be removed in 4.0. Use the MemcachedFactory::create() method from Dsn component instead.
*/
public function testCreateConnectionDeprecated()
{
$client = MemcachedAdapter::createConnection(array(), array(
'libketama_compatible' => false,
'distribution' => 'modula',
'compression' => true,
'serializer' => 'php',
'hash' => 'md5',
));

$this->assertSame(\Memcached::SERIALIZER_PHP, $client->getOption(\Memcached::OPT_SERIALIZER));
$this->assertSame(\Memcached::HASH_MD5, $client->getOption(\Memcached::OPT_HASH));
$this->assertTrue($client->getOption(\Memcached::OPT_COMPRESSION));
$this->assertSame(0, $client->getOption(\Memcached::OPT_LIBKETAMA_COMPATIBLE));
$this->assertSame(\Memcached::DISTRIBUTION_MODULA, $client->getOption(\Memcached::OPT_DISTRIBUTION));
$client = MemcachedAdapter::createConnection('memcached://localhost');

$this->assertInstanceOf(\Memcached::class, $client);
}

/**
* @group legacy
* @dataProvider provideBadOptions
* @expectedException \ErrorException
* @expectedExceptionMessage constant(): Couldn't find constant Memcached::
Expand All @@ -81,6 +76,9 @@ public function provideBadOptions()
);
}

/**
* @group legacy
*/
public function testDefaultOptions()
{
$this->assertTrue(MemcachedAdapter::isSupported());
Expand All @@ -93,6 +91,7 @@ public function testDefaultOptions()
}

/**
* @group legacy
* @expectedException \Symfony\Component\Cache\Exception\CacheException
* @expectedExceptionMessage MemcachedAdapter: "serializer" option must be "php" or "igbinary".
*/
Expand All @@ -106,6 +105,7 @@ public function testOptionSerializer()
}

/**
* @group legacy
* @dataProvider provideServersSetting
*/
public function testServersSetting($dsn, $host, $port)
Expand Down Expand Up @@ -163,6 +163,7 @@ public function provideServersSetting()
}

/**
* @group legacy
* @dataProvider provideDsnWithOptions
*/
public function testDsnWithOptions($dsn, array $options, array $expectedOptions)
Expand Down
12 changes: 12 additions & 0 deletions 12 src/Symfony/Component/Cache/Tests/Adapter/PredisAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ public static function setupBeforeClass()
self::$redis = new \Predis\Client(array('host' => getenv('REDIS_HOST')));
}

/**
* @group legacy
* @expectedDeprecation The %s() method is deprecated since version 3.4 and will be removed in 4.0. Use the RedisFactory::create() method from Dsn component instead.
*/
public function testCreateConnectionDeprecated()
{
RedisAdapter::createConnection('redis://'.getenv('REDIS_HOST'));
}

/**
* @group legacy
*/
public function testCreateConnection()
{
$redisHost = getenv('REDIS_HOST');
Expand Down
19 changes: 18 additions & 1 deletion 19 src/Symfony/Component/Cache/Tests/Adapter/RedisAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,30 @@

use Symfony\Component\Cache\Adapter\AbstractAdapter;
use Symfony\Component\Cache\Adapter\RedisAdapter;
use Symfony\Component\Dsn\Factory\RedisFactory;

class RedisAdapterTest extends AbstractRedisAdapterTest
{
public static function setupBeforeClass()
{
parent::setupBeforeClass();
self::$redis = AbstractAdapter::createConnection('redis://'.getenv('REDIS_HOST'));
self::$redis = RedisFactory::create('redis://'.getenv('REDIS_HOST'));
}

/**
* @group legacy
* @expectedDeprecation The %s() method is deprecated since version 3.4 and will be removed in 4.0. Use the RedisFactory::create() method from Dsn component instead.
*/
public function testCreateConnectionDeprecated()
{
$client = RedisAdapter::createConnection('redis://'.getenv('REDIS_HOST'));

$this->assertInstanceOf(\Redis::class, $client);
}

/**
* @group legacy
*/
public function testCreateConnection()
{
$redisHost = getenv('REDIS_HOST');
Expand All @@ -45,6 +60,7 @@ public function testCreateConnection()
}

/**
* @group legacy
* @dataProvider provideFailedCreateConnection
* @expectedException \Symfony\Component\Cache\Exception\InvalidArgumentException
* @expectedExceptionMessage Redis connection failed
Expand All @@ -64,6 +80,7 @@ public function provideFailedCreateConnection()
}

/**
* @group legacy
* @dataProvider provideInvalidCreateConnection
* @expectedException \Symfony\Component\Cache\Exception\InvalidArgumentException
* @expectedExceptionMessage Invalid Redis DSN
Expand Down
26 changes: 23 additions & 3 deletions 26 src/Symfony/Component/Cache/Tests/Simple/MemcachedCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

namespace Symfony\Component\Cache\Tests\Simple;

use Symfony\Component\Cache\Adapter\AbstractAdapter;
use Symfony\Component\Cache\Simple\MemcachedCache;
use Symfony\Component\Dsn\Factory\MemcachedFactory;

class MemcachedCacheTest extends CacheTestCase
{
Expand All @@ -29,7 +29,7 @@ public static function setupBeforeClass()
if (!MemcachedCache::isSupported()) {
self::markTestSkipped('Extension memcached >=2.2.0 required.');
}
self::$client = AbstractAdapter::createConnection('memcached://'.getenv('MEMCACHED_HOST'));
self::$client = MemcachedFactory::create('memcached://'.getenv('MEMCACHED_HOST'));
self::$client->get('foo');
$code = self::$client->getResultCode();

Expand All @@ -40,11 +40,25 @@ public static function setupBeforeClass()

public function createSimpleCache($defaultLifetime = 0)
{
$client = $defaultLifetime ? AbstractAdapter::createConnection('memcached://'.getenv('MEMCACHED_HOST'), array('binary_protocol' => false)) : self::$client;
$client = $defaultLifetime ? MemcachedFactory::create('memcached://'.getenv('MEMCACHED_HOST'), array('binary_protocol' => false)) : self::$client;

return new MemcachedCache($client, str_replace('\\', '.', __CLASS__), $defaultLifetime);
}

/**
* @group legacy
* @expectedDeprecation This "%s" method is deprecated.
*/
public function testCreateConnection()
{
$client = MemcachedCache::createConnection('memcached://localhost');

$this->assertInstanceOf(\Memcached::class, $client);
}

/**
* @group legacy
*/
public function testOptions()
{
$client = MemcachedCache::createConnection(array(), array(
Expand All @@ -63,6 +77,7 @@ public function testOptions()
}

/**
* @group legacy
* @dataProvider provideBadOptions
* @expectedException \ErrorException
* @expectedExceptionMessage constant(): Couldn't find constant Memcached::
Expand All @@ -82,6 +97,9 @@ public function provideBadOptions()
);
}

/**
* @group legacy
*/
public function testDefaultOptions()
{
$this->assertTrue(MemcachedCache::isSupported());
Expand All @@ -94,6 +112,7 @@ public function testDefaultOptions()
}

/**
* @group legacy
* @expectedException \Symfony\Component\Cache\Exception\CacheException
* @expectedExceptionMessage MemcachedAdapter: "serializer" option must be "php" or "igbinary".
*/
Expand All @@ -107,6 +126,7 @@ public function testOptionSerializer()
}

/**
* @group legacy
* @dataProvider provideServersSetting
*/
public function testServersSetting($dsn, $host, $port)
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.