-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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
Conversation
@@ -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" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
|
||
try { | ||
$type = ConnectionFactory::getType($dsn); | ||
} catch (\Symfony\Component\Dsn\Exception\InvalidArgumentException $e) { |
There was a problem hiding this comment.
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.
Should be targetting 3.4, and should update FrameworkBundle also. |
try { | ||
$type = ConnectionFactory::getType($dsn); | ||
} catch (DsnInvalidArgumentException $e) { | ||
throw new InvalidArgumentException($e->getMessage(), 0, $e); |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
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://
)
There was a problem hiding this comment.
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 😄
There was a problem hiding this comment.
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"
Now part of #24267 |
This PR deprecate the Cache's CreateConnection methods in favor of Dsn's one.
Tests won't pass until Dsn component will be released