A way to add static functions to YiiBase.
Yii::extend(array('funcName' => function() {}));
Yii::extend(array('className'));
class className {
static function foo() {}
}
Yii::funcName();
Yii::foo();
class YiiBase {
...
private static $_extendsMethods = array();
private static $_extendsClasses = array();
public static function extend($extends)
{
foreach ($extends as $name => $extend)
{
if (is_int($name))
self::$_extendsClasses[] = $extend;
else
self::$_extendsMethods[$name] = $extend;
}
}
public static function __callStatic($name, $arguments)
{
if (isset(self::$_extendsMethods[$name]))
{
call_user_func_array(self::$_extendsMethods[$name], $arguments);
}
else
{
foreach (self::$_extendsClasses as $class)
{
if (method_exists($class, $name))
{
call_user_func_array($class . '::' . $name, $arguments);
}
}
}
}
...
}
It probably won’t happen often but you sometimes might want to extend YiiBase.
I need to extend Yii:t() but don’t really want to have it in a helper class.