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
Code cleanup #27
Code cleanup #27
Conversation
Apologies for the lack of specificity but the library was so small that a quick rewrite that breaks BC was more efficient. Hope you have time to review and provide feedback. Some things this PR does:
|
…; use the transportfactory instead
I'm gonna let this sit here for a bit while I test it in my production application. |
Co-authored-by: Alexander Makarov <sam@rmcreative.ru>
Co-authored-by: Alexander Makarov <sam@rmcreative.ru>
Co-authored-by: Alexander Makarov <sam@rmcreative.ru>
Co-authored-by: Alexander Makarov <sam@rmcreative.ru>
Co-authored-by: Alexander Makarov <sam@rmcreative.ru>
Co-authored-by: Alexander Makarov <sam@rmcreative.ru>
Is the completion of the work planned ? |
Yes definitely. This branch is already in production so I'm pretty sure it works. |
@SamMousa shouldn't readme be adjusted? |
Hmm, good point, very probably yes. Will try to make some time to finish this! |
I would recommend allowing them because if someone creates a new Transport that has a lot of 'options' it's much easier to see what they are rather than appending them to the 'dsn' string. I find the symfony mailer to be kind of a backward step compared to Swift in a few areas. The configuration being one of them. He even expects the dsn string to be in a global constant. That's why he prefers the single string over an array. However, internally the DSN object parses the the string and converts it to individual settings. To me it just makes more sense to skip all that and use an array - much cleaner looking configuration. Of course, I kind of opinionated... Oh well. |
Also, I would recommend using 'protected' instead of 'private'. This allows the classes to be extended. Quote from the "About Yii" section of the "Guide": And since this is an official Yii extension rather than an independent library it makes sense to me to follow that "extensible" aspect. |
You keep coming back to this, but I believe it is a fundamental misunderstanding of how to write extensible code. Code being extensible does not have to mean that classes are extendable.
The library we use uses a DSN though, and the DSN object inherently loses features like Thinking it through a bit more I'm pretty sure that even leaving in the This is way cleaner: [
'class' => Mailer::class,
'dsn' => "sendgrid+api://{$env->get('SENDGRID')}@default"
] And if you need a custom factory implement that: [
'class' => Mailer::class,
'transportFactory' => new Transport(new MyTransportFactory()),
'dsn' => "my-custom-protocol://{$env->get('SENDGRID')}@default"
] |
Composition it is then. Of course, you realize that the Mailer class extends BaseMailer... I don't see that strictly using a 'dsn' element is necessarily cleaner. When using certain Transports, yes, it's cleaner. But not for all Transports.
That would be a very long 'dsn' string. And, again, the DSN object just parses the string to get back to what's clearly displayed in the array. |
I guess if I wanted to use |
I do, there's no easy way around it. Also realize that the framework is +- 10 years old, its core code is not a best practice in 2022. |
samdark added this to the 3.0.0 milestone 9 days ago does that mean never? |
No. That means it will be a major release of this exact extension. |
@SamMousa thank you for reworking this! I'm wondering if we could also include |
Not in this pr. Let's do that after maybe |
just curious, what is the ETA on this PR?
thanks for your hard work! 😊 |
Yes. Google is your friend. |
@SamMousa sorry it took so long. Would you please help closing issues this PR solves? Thanks. |
@samdark need a tag |
@SamMousa, @Krakozaber is readme alright? |
Yes it looks good and both configuration methods have test cases. |
The readme has an error in the first configuration. The transport array can have a 'dsn" or it can have the other fields, 'scheme', etc. But it cannot have both. If the code finds a 'dsn' it will ignore the other fields. Incorrect:
Correct:
|
Good catch, can you make a PR for that change @nd4c ? |
Also, I believe the 'scheme' settings is better to be left out. 'scheme' => 'smtps' is kind of misleading. It doesn't exactly force ssl, but rather causes the code to choose a different transport. I forget the details, but it's the 'port' => '465' that cause the code to use ssl. And the default transport works better than the 'smtps' transport. So the better config would be:
|
I've never dones a PR before. Any tips? |
Personally I believe you should be using DSN in all cases. The underlying library uses DSN and by not using it all you do is lose functionality.
For these simple things you can just do them inside Github and it will do most of the meta-work for you. Good luck! |
Actually the underlying library uses the inidividual fields. It will convert any DSN string to individual attributes on it's DSN object. And not all transports are easy to for a developer to "read" as a DSN string. (And for that matter, the DSN string is not technically a DSN, but rather a list of configuration settings...) I will work on the README.md file. |
All true, but the relevant part is the fact that the DSN is an opaque string. In general the pattern is wrong. Any new feature added to the underlying library requires us to write and maintain new code, tests and documentation... instead we could just say: use a DSN, check the docs: https://symfony.com/doc/current/mailer.html and be done :-) I mean I don't know based on our readme how I'd configure it to use Sendgrid.. The array syntax doesn't add any discoverability... I know however that if I just use the DSN I'm good to go. |
This is a big cleanup PR that fixes a plethora of smaller issues and rewrites other parts.