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

[Cache][Lock] Use Dsn component to create connections #24323

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 2 commits into from

Conversation

jderusse
Copy link
Member

Q A
Branch? 3.4
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? yes
Tests pass? not yet
Fixed tickets
License MIT
Doc PR NA

This PR deprecate the Cache's CreateConnection methods in favor of Dsn's one.

Tests won't pass until Dsn component will be released

@@ -30,7 +30,8 @@
"cache/integration-tests": "dev-master",
"doctrine/cache": "~1.6",
"doctrine/dbal": "~2.4",
"predis/predis": "~1.0"
"predis/predis": "~1.0",
"symfony/dsn": "3.4"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

symfony/dsn is a requirement to keep BC. But in sf 4.0 in could be a suggesiton.

What is the upgrade path to deprecate a requirement?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have none: just read UPRGRADE files, that's what we did in the past

@nicolas-grekas nicolas-grekas changed the title WIP: [Cache] Use Dsn component to create connections [Cache] Use Dsn component to create connections Sep 26, 2017
@nicolas-grekas nicolas-grekas added this to the 3.4 milestone Sep 26, 2017

try {
$type = ConnectionFactory::getType($dsn);
} catch (\Symfony\Component\Dsn\Exception\InvalidArgumentException $e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing "use" statement to shorten the FQCN here.

@nicolas-grekas
Copy link
Member

Should be targetting 3.4, and should update FrameworkBundle also.

@jderusse jderusse changed the base branch from master to 3.4 September 26, 2017 10:16
try {
$type = ConnectionFactory::getType($dsn);
} catch (DsnInvalidArgumentException $e) {
throw new InvalidArgumentException($e->getMessage(), 0, $e);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just asking: if in the catch we just throw an exception ... would it better to remove the catch entirely to throw the original and more specific DsnInvalidArgumentException ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 for throwing DsnInvalidArgumentException, as that already is a framework specific exception

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be a BC break?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would yes, so the rethrow is required actually

if (0 === strpos($dsn, 'memcached://')) {
return MemcachedAdapter::createConnection($dsn, $options);

switch ($type) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this switch logic be moved to the Dsn component itself to avoid duplicating it in every component using it? Something like this:

// Before
switch ($type) {
    case ConnectionFactory::TYPE_MEMCACHED:
        return MemcachedConnectionFactory::createConnection($dsn, $options);
    case ConnectionFactory::TYPE_REDIS:
        return RedisConnectionFactory::createConnection($dsn, $options);
}

// After
return ConnectionFactory($type, $dsn, $options);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

such methods already exists in the Dsn component => ConnectionFactory::create($dsn, $options).

But this methods may return anything (\Pdo, \Ldap, etc...). By using directly the Dsn factory, we are changing the behavior of this method (which previously throws an exception when the DSN wasn't neither redis://, neither memcached://)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't understand this ... but if Nicolas and you say it's correct, then I'm sure it's correct 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the following userland app code

try {
   $c = AbstractAdapter::createConnection('mysql://localhost');
  echo 'got a '.get_class($c);
} catch (InvalidArgumentException $e) {
  echo 'expected faillure';
}

using the switch => expected faillure
using Dsn\ConnectionFactory::create => got a \Pdo

It sounds like a BC Break, but IMO i'm also fine to use whats you suggest and saying "we are not responsible of the output of this method if you enter weird things"

@nicolas-grekas nicolas-grekas mentioned this pull request Sep 28, 2017
2 tasks
@jderusse jderusse changed the title [Cache] Use Dsn component to create connections [Cache][Lock] Use Dsn component to create connections Sep 28, 2017
@nicolas-grekas
Copy link
Member

Now part of #24267

@jderusse jderusse deleted the dsn-cache branch August 2, 2019 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.