-
-
Notifications
You must be signed in to change notification settings - Fork 72
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
Unable to extend compose()
, unable to extend render()
#14
Comments
What's your proposal? |
Which class scope are you refering exaclty?
It is much magic as $params['widget'] in What exactly is the problem? |
The problem is class can not be extended due to bad design. While it obvious, ok, example: class MyMailer extends \yii\mailer\BaseMailer
{
// ...
public function compose($view = null, array $params = [])
{
// my own logic, but i want use $this->render() in my implementation too
$this->render($view['html'], $params, $this->htmlLayout);
}
} In child classes public function compose($view = null, array $params = [])
{
if (!array_key_exists('message', $params)) {
$params['message'] = $message;
}
// ...
$this->_message = $message;
// render call
$this->_message = null;
// ...
}
public function render($view, $params = [], $layout = false)
{
// $this->_message used there and you can't set its value from child classes
} Its what i call voodoo magic which make class complettely unextensible. While i understand that you try to avoid override But in general i think its complettely overcoded + ugly hacked. You can just mark |
Or there is 10 other methods how to solve trouble without hacks. For example extend |
Well, in this case this issue does not belong to the
First of all it not my code, see: The change, which you complain on, has been introduced at yiisoft/yii2#4147
It was so at the beginning. |
@klimov-paul Ok, thanks. Created issue in corresponding repo: yiisoft/yii2#9260
Sometimes its hard to put aside emotions, especially when you see hacks like: $this->_message = $message;
// call method where $this->_message will be used
$this->_message = null; Sorry :) |
@klimov-paul Because of
$this->_message
private variable. Also all this$params['message']
workaround looks like real voodoo magic. Maybe its good idea to replace it with something smart?The text was updated successfully, but these errors were encountered: