Laravel - 注册装饰器
Laravel - Registering a Decorator
我正在尝试在 Laravel 容器中为 Mailer
服务实施装饰器模式。遵循 this page, as well as official documentation.
上的语法
我正在 AppServiceProvider
中注册 MailerDecorator
(在 app.php
配置中注册)register
方法。
$this->app->extend(Mailer::class, function ($mailer) {
return new MailerDecorator($mailer);
});
很遗憾,装饰器未注册,应用程序仍在使用旧实现。
有没有办法调试容器?我错过了什么吗?
谢谢!
Laravel Mailer class 与别名 mailer
绑定,因此您可以尝试使用 mailer
别名而不是 Mailer::class
来注册 Decorator。
$this->app->extend('mailer', function ($mailer) {
return new MailerDecorator($mailer);
});
我正在尝试在 Laravel 容器中为 Mailer
服务实施装饰器模式。遵循 this page, as well as official documentation.
我正在 AppServiceProvider
中注册 MailerDecorator
(在 app.php
配置中注册)register
方法。
$this->app->extend(Mailer::class, function ($mailer) {
return new MailerDecorator($mailer);
});
很遗憾,装饰器未注册,应用程序仍在使用旧实现。
有没有办法调试容器?我错过了什么吗?
谢谢!
Laravel Mailer class 与别名 mailer
绑定,因此您可以尝试使用 mailer
别名而不是 Mailer::class
来注册 Decorator。
$this->app->extend('mailer', function ($mailer) {
return new MailerDecorator($mailer);
});