如何覆盖laravel 5中刀片的默认转义功能?

如何覆盖laravel 5中刀片的默认转义功能?

问题描述:

I almost solved my problem in this question. Now I must find a way to override the default blade escape function. I think there's a way to create a class that extends and override the behavior of BladeCompiler class, this way I could make something like this:

class MyCustomCompiler extends BladeCompiler{
   function compileEscapedEchos($value){
        return parent::compileEscapedEchos(utf8_encode($value));
    }
}

If I could do it, I only must make laravel use MyCustomCompiler instead BladeCompiler. How can I do it?

我几乎在这个问题。 现在我必须找到一种方法来覆盖默认的刀片转义函数。 我认为有一种方法可以创建一个扩展和覆盖BladeCompiler类行为的类,这样我可以做出这样的事情: p> \ n

 类MyCustomCompiler扩展了BladeCompiler {
 function compileEscapedEchos($ value){
 return parent :: compileEscapedEchos(utf8_encode($ value)); 
} 
} 
  code>   pre> 
 
 

如果我能做到,我只能使用MyCustomCompiler代替BladeCompiler。 我该怎么办? p> div>

You don't even have to override the compiler, just do this in a Service Provider:

Blade::setEchoFormat('e(utf8_encode(%s))');

This will change how {{ ... }} is compiled. The default format is e(%s).