Hi,
I need to extends the SwiftMailer method with my own implementation because the call of "file_get_contents" in attach method fails because a self signed certificate in my domain.
After I extend the class my custom "attach" method not works because the parent object (SwiftMailer) has declared all of his own methods as private.
Why not use protected to declare these methods?
I think there are not reason to use private methods in Drupal plugins... maybe in some cases has some reasons, but I can´t find the reasons here.
Maybe Reflection is a solution but i wan´t use it.
Is it possible to change all methods from "private" to "protected"?
protected function attach(Swift_Message $m, array $files) { ... }
Greetings!
Comments
Comment #2
jncrucesComment #3
jncrucesComment #4
jncrucesThis patch can help.
Comment #5
agoradesign commented+1 for this. Just had a similar use case. I needed to build up SMTP connection to a self-signed certificate. I'll probably open another issue suggesting to fire an event allowing to manipulate these parameters. But nevertheless it's not nice that - for whatever reason one might have - overriding the swiftmailer plugin results in duplicating all those private functions, just because they are private
Comment #6
agoradesign commentedComment #7
webflo commentedI am fine with changing the private methods to protected, but this was done because these methods are not meant to be API or extension points.
Lets evaluate other solutions first:
#5 could be done via hook_swiftmailer_alter.
Regarding the file_get_contents problem: maybe we should replace file_get_contents with a proper http client, which then could be configured via dependency injection.
Comment #8
agoradesign commentedThat's correct, thanks!
Comment #9
adamps commentedDrupal core has 23 instances of "private function" and 1760 of "protected function". This suggests that the idea is that Drupal is customisable software - without the need for developers to come to the maintainers and "prove" that they have a valid customisation requirement.
Perhaps we could set the functions to protected with a comment that the maintainers reserve the right to change the interface without notice?
@webflo would you be happy with that?
Comment #10
geek-merlinYes, protected methods are part of an inheritance API. There are quite some discussions around that in core, the tendency to being less open to "monkeypatching" by subclassing.
The methods we currently have look to me as quite stable, so i'd be fine with setting that to protected and giving API guarantee.
If there are strong objections about that, we can mark them protected, but also @internal, meaning "you can monkey-patch this, but do not rely on this".
Comment #11
adamps commented#10 makes sense to me.
By default we won't add @internal, but @webflo (or anyone else) we can if you want. If so please set status back to "Needs Works" for that.
We can wait 1 week before we commit this.
Comment #12
agoradesign commentedIs there a general rule within Drupal on how binding protected functions are in an API contract manner? From my view, everything that's not defined in an interface, is potentially subject to change (even interfaces changes over time in contrib modules, but they should be at least planned as being stable and final). Of course I expect mentioning these changes in release notes and change records.
Imho every dev should anyway try other extension possibilities first, before swapping a service by subclassing the original. Often we have the possibility with plugins, events, alter hooks, etc. But in the end, sometimes your requirements are so custom to swap some services. And this is so great and powerful in D8, that you can do this so easily and often only involving a few lines of code
Comment #13
agoradesign commentedSo I'd vote +1 for changing to protected. But why not leave an extra line comment in every signature we change here, that this is potentially subject to change
Comment #14
adamps commented#13 Yes we could and I like the proposal in #10 that the line comment for "subject to change" would be @internal.
If anyone wants to post a patch adding @internal that's fine by me.
Comment #15
adamps commentedProbably
massageMessageBody()should be protected not public??Comment #16
agoradesign commentedmakes sense
Comment #17
adamps commentedOK taking in the balance of opinion it seems like we should
Setting to "Needs work" for that.
Comment #18
adamps commentedComment #20
adamps commentedComment #21
geek-merlinLGTM.
Comment #23
adamps commentedGreat thanks