【发布时间】:2018-11-09 11:22:00
【问题描述】:
我想重写vendor/laravel/framework/src/Illuminate/View/Compilers/BladeCompiler.php中的一个函数
或者更确切地说是该文件使用的特征Illuminate\View\Compilers\Concerns\CompilesEchos.php 之外的函数。但是我找不到关于如何覆盖包的非常明确的信息。有人可以帮我理解一下。
我了解我需要扩展 BladeCompiler
我们称之为 MyBladeCompiler
class MyBladeCompiler extends BladeCompiler
{
public function compileEchoDefaults($value)
{
return 'test';
return preg_replace('/^(?=\$)(.+?)(?:\s+or\s+)(.+?)$/si', 'isset($1) ? $1 : $2', $value);
}
}
我现在想将它注册为要使用的新类。我明白这应该在服务提供商中完成,但是如何?
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
$this->app->bind(BladeCompiler::class, MyBladeCompiler ::class);
}
}
这不起作用
【问题讨论】: