What's with the shell classes extending base classes?

In Yii 2 we’re seeing a lot of shell classes that do nothing besides extend a base class. For example:

  • Yii is an empty class that extends yii\BaseYii

  • yii\helpers\Json is an empty class that extends yii\helpers\BaseJson

  • yii\helpers\Html is an empty class that extends yii\helpers\BaseHtml

Does anyone know the reason for this design pattern? Why not just define the yii\BaseYii implementation directly in Yii, the yii\helpers\BaseJson implementation directly in yii\helpers\Json, etc.?

-Brandon

http://www.yiiframework.com/doc-2.0/guide-helper-overview.html#customizing-helper-classes

Aha! Thanks for the pointer, Sam!

Took me a minute to wrap my head around this, so to clarify: This allows you to helper classes at the framework level - in other words so you can modify the behavior of helper functions that Yii itself is calling (e.g. when Yii’s own classes call yii\helpers\ArrayHelper::merge()).

Previously this would have required a core file hack. This is much nicer!

-Brandon

Great question, I always wondered why is it implemented like this.

It’s the same in Yii 1, with YiiBase class.

Yep, we expanded YiiBase idea to helpers.