Skip to content

[Notifier] Change Dsn api #39585

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

Merged
merged 1 commit into from
Jan 14, 2021
Merged

[Notifier] Change Dsn api #39585

merged 1 commit into from
Jan 14, 2021

Conversation

OskarStark
Copy link
Contributor

@OskarStark OskarStark commented Dec 21, 2020

Q A
Branch? 5.x, BC BREAK, but experimental
Bug fix? yes
New feature? yes
Deprecations? no
Tickets Fix #39533
License MIT
Doc PR ---

This PR

  • adds a new getOptions() method, which could be helpful and also improves testability instead of dealing with reflections
  • makes the __construct() method accept only a dsn as string
  • removes fromString() method
  • afterwards you can always rely on getOriginalDsn() method, like described by its return type, before it returned null when Dsn class was instantiated via the constructor and a TypeError was thrown
  • refactored the tests

This should be done for the Mailer Dsn class too, but this class is not experimental anymore... 🤔

Comment on lines +190 to +194
yield [
'',
'scheme://localhost?empty=',
'empty',
];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would prefer to return null in case of an empty string, wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@fabpot thoughts?

@OskarStark OskarStark force-pushed the fix-39533 branch 3 times, most recently from a809ab7 to 6afcbc0 Compare December 25, 2020 10:58
@OskarStark
Copy link
Contributor Author

I would love to get your feedback on this @fabpot 👍


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

Choose a reason for hiding this comment

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

I don't see why we should forbid the usage of the constructor.

Copy link
Contributor Author

@OskarStark OskarStark Jan 6, 2021

Choose a reason for hiding this comment

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

Otherwise you would end up with the same problem.... original DSN is not set, but used heavily in exceptions.

See explanation in the referenced issue please.

Copy link
Member

Choose a reason for hiding this comment

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

Instead, would it possible to create the "DSN as string" from all the parts given in the constructor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it would, but it is not the "original"/"provided" one, so let's say we can't parse anything or have magic chars or .... we will not use the provided one in the exception message, but a generated one which is not what I would expect 🤷‍♂️

So this would be more a "toString" instead of a "original dsn"...

Besides this, its a class to deal with DSN's which are strings per design, so I would go with strings only, another positive aspect I encountered while reworking all tests for the bridges: the dsn is much more readable as a string ❗

Copy link
Member

Choose a reason for hiding this comment

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

I get it now :) So, what about removing the fromString() method instead and pass the DSN (a string) as the only argument to the constructor?

Copy link
Member

Choose a reason for hiding this comment

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

@OskarStark Have you seen my comment above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Didn't see the comment, will have a look later or tomorrow 👍🏻

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I get it now :) So, what about removing the fromString() method instead and pass the DSN (a string) as the only argument to the constructor?

Yes we can 👍 Will do

@OskarStark OskarStark force-pushed the fix-39533 branch 2 times, most recently from e5568cd to c807a08 Compare January 8, 2021 06:36
@fabpot
Copy link
Member

fabpot commented Jan 13, 2021

Can you have a look at the failing tests?

@OskarStark
Copy link
Contributor Author

All green now @fabpot 👍

@OskarStark OskarStark changed the title [Notifier] Close Dsn api [Notifier] Change Dsn api Jan 13, 2021
@OskarStark
Copy link
Contributor Author

I also streamlined some changelog files.

@fabpot I would love to hear your feedback on:

This should be done for the Mailer Dsn class too, but this class is not experimental anymore... 🤔

and #39585 (comment)

`public function __construct(string $token, string $accountReference, string $from, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)`
to:
`public function __construct(string $email, string $password, string $accountReference, string $from, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)`
* The bridge is not marked as `@experimental` anymore.
Copy link
Member

Choose a reason for hiding this comment

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

Instead of going back and forth on this, I've documented the conventions in the docs: https://github.com/symfony/symfony-docs/pull/14830/files

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

{
return $this->options;
}

public function getPath(): ?string
{
return $this->path;
}

public function getOriginalDsn(): string
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: What about renaming it to __toString()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would avoid that, because that would be yet another BC break

@fabpot
Copy link
Member

fabpot commented Jan 14, 2021

Thank you @OskarStark.

@fabpot fabpot merged commit 1eb849d into symfony:5.x Jan 14, 2021
@fabpot fabpot mentioned this pull request Apr 18, 2021
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.

[Bug] [Notifier] [Mailer] getOriginalDsn() cannot be used when Dsn is instantiated via new Dsn()
4 participants