Skip to content

[Lock] add the DSN object #33200

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

Simperfit
Copy link
Contributor

Q A
Branch? 4.4
Bug fix? no
New feature? Sort of
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets Linked to #32546
License MIT
Doc PR none atm

For the lock component we are using dsn for flock and for testing that we have DSN for redis and for memcache directly via the cache component, we could go one step futher and pass the dsn to the adapter directly. but that could be done in another PR.

@Simperfit Simperfit force-pushed the feature/add-dns-object-for-lock-component branch from 900a181 to 253a2a3 Compare August 16, 2019 06:29
@Simperfit Simperfit force-pushed the feature/add-dns-object-for-lock-component branch from 253a2a3 to 27f35c7 Compare August 16, 2019 06:30
@fabpot
Copy link
Member

fabpot commented Aug 16, 2019

If we go down this road, I'd like a full PR. For instance, it's not possible to configure some adapter via a DSN like the Doctrine one. Can you work on this so we get the full picture?

@OskarStark
Copy link
Contributor

Is this one related #24267

@Simperfit
Copy link
Contributor Author

@OskarStark It was a first draft but we are going to implement in the lock as an exemple to see what will be the good path

private $path;
private $options;

public function __construct(string $scheme, string $host, ?string $user = null, ?string $password = null, ?int $port = null, ?string $path = null, array $options = [])
Copy link
Contributor

Choose a reason for hiding this comment

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

should be private to be immutable

$options);
}

public function getScheme(): string
Copy link
Contributor

@OskarStark OskarStark Aug 16, 2019

Choose a reason for hiding this comment

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

Suggested change
public function getScheme(): string
public function scheme(): string

I am 👍 for no get-prefix. Same for the others

Except getOption(...)

$this->options = $options;
}

public static function isValid(string $dsn)
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure this is a good idea, by having this method the Dsn object could be instantiated and be in an invalid state.

Why not throw an exception instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I saw this is using a parameter and to the objects state... Then why using it? You can wrap your code in try-catch-block to achieve the same goal, right?

private $options;

public function __construct(string $scheme, string $host, ?string $user = null, ?string $password = null, ?int $port = null, ?string $path = null, array $options = [])
{
Copy link
Contributor

Choose a reason for hiding this comment

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

You should assert, that the string values are not empty IMO


parse_str($parsedDsn['query'] ?? '', $options);

return new self($parsedDsn['scheme'],
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return new self($parsedDsn['scheme'],
return new self(
$parsedDsn['scheme'],

@nicolas-grekas nicolas-grekas added this to the next milestone Aug 17, 2019
@nicolas-grekas
Copy link
Member

I think I'm 👎 here. We don't want to cover this with the BC policy.

@nicolas-grekas
Copy link
Member

Instead, I'd suggest improving StoreFactory to make it able to create PdoStore and ZookeeperStore (check that all supported stores can be created by it actually)

@Simperfit
Copy link
Contributor Author

@nicolas-grekas So you are -1 with adding DSN object per component ? What can we do to improve the parsing of DSN ? this is not only the lock but messenger too see #32566 as another exemple.

@fabpot
Copy link
Member

fabpot commented Feb 3, 2020

Closing as we won't merge it only for Lock. Still not convinced this is something we want/need.

@fabpot fabpot closed this Feb 3, 2020
@nicolas-grekas nicolas-grekas modified the milestones: next, 5.1 May 4, 2020
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