我想要什么
扩展供应商使用的 Laravel 类,特别是这个:https://github.com/laracasts/flash和 Flash/Message.php
类。
我为什么要
为了自定义目的添加一些类参数。
我尝试了什么
我在谷歌搜索和浏览其他问题时发现的所有内容。
我已经创建了自己的服务提供者:
use Laracasts\Flash\FlashServiceProvider as BaseServiceProvider;
class FlashServiceProvider extends BaseServiceProvider
{
public function register()
{
$this->app->singleton( 'flash', function() {
return $this->app->make( 'App\Extensions\Laracasts\Flash\FlashNotifier' );
} );
}
}
甚至成功地将自定义函数添加到 App\Extensions\Laracasts\Flash\FlashNotifier
类。
还是不行
尽管我已经成功地扩展了 FlashNotifier
类。我仍然有问题,因为它一直在使用原始的 Messages
类,而不是我的。
问题
如何强制我的扩展 FlashNotifier
类使用我的 Messages
类版本而不是原始版本?
最佳答案
您可以采用不同的方法,而不是扩展类。
创建 laracasts/flash 的分支,然后您可以将其加载到您的项目中
loading a package from a VCS repository 的 Composer 文档
来自文档
There are a few use cases for this. The most common one is maintaining your own fork of a third party library. If you are using a certain library for your project and you decide to change something in the library, you will want your project to use the patched version...
关于php - 扩展供应商使用的 Laravel 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46801377/