Extending helpers

Yes it would.

EDIT: Later in the day I realized there would be no BC break because I wouldn’t use Yii 3 except in a completely new project and in that case I can probably adapt to whatever the framework constraints are.

1 Like

In 1. is “you” the framework author?

I don’t understand 2. And cui bono?

How would you suggest using composition instead of…?

class HtmlPurifier extends \yii\helpers\HtmlPurifier
{
    const CONFIG = ['blah' => 'blah'];

    public static function process($content, $config = null)
    {
        return parent::process($content, self::CONFIG + (is_array($config) ? $config : []));
    }
}
  1. Yes.
  2. Again, framework authors. That is a bit more control about framework users endless creativity.
class HtmlPurifier
{
    const CONFIG = ['blah' => 'blah'];

    public static function process($content, $config = null)
    {
        return \yii\helpers\HtmlPurifier::process($content, self::CONFIG + (is_array($config) ? $config : []));
    }
}

But the composition part wasn’t really about helpers but about non-static classes.

I wonder it would not be easier to separate all helpers from the framework as a separate component ?

How would that make a difference?

But what about another approach: Implement the helpers as trait. This way a final “custom” helper implementation could be composed.