Assuming yii2-app-advanced. I would like to override the base implementation of \yii\helpers\Inflector::hasIntl() which is used (indirectly) by yii\web\Response.
original code
protected static function hasIntl()
{
return extension_loaded('intl');
}
the code I want
<?php
namespace backend\components;
class Inflector extends \yii\helpers\Inflector
{
protected static function hasIntl()
{
return false;
}
}
So, I create backend\components\Inflector extending yii\helpers\Inflector and override the method as shown above.
Then in backend/config/bootstrap.php I add:
Yii::$container->set('\yii\helpers\Inflector', '\backend\components\Inflector');
But is not using the custom implementation. It keeps using the original one. So, questions:
- why is not working?
- a good alternative solution? (a posted an ugly one)
I have read Yii2 extend or replace core class and used this Yii::$container->set method before, but in this case is not working, even if done like:
Yii::$container->set('\yii\helpers\Inflector', [
'class' => '\backend\components\Inflector',
]);
yii\helpers\Inflectoryourself and have it extendyii\helpers\BaseInflector(which contains the default implementation). Not sure that's what you're looking for (and not sure it even works, but some people mention it). - Jeto