简体   繁体   English

Laravel:在发布之前永久覆盖来自 Laravel Package 的依赖项配置

[英]Laravel: Permanently override config of dependencies from a Laravel Package before publishing them

I am developing a Laravel Package which installs a list of dependencies.我正在开发一个安装依赖项列表的 Laravel Package。 The dependencies have their own configuration files to be published after installation.依赖项有自己的配置文件,安装后要发布。

What we need is to auto (to avoid doing it manually) modify the config files of these dependencies by our package before/after publishing them and placing them in app/config .我们需要的是在发布它们之前/之后通过我们的 package 自动(避免手动)修改这些依赖项的配置文件并将它们放在app/config中。

I found some solutions like using mergeConfigFrom() in register method of Package's service provider.我找到了一些解决方案,例如在 Package 的服务提供者的注册方法中使用mergeConfigFrom() But it doesn't modify file content itself, just loads the merged config.但它不会修改文件内容本身,只是加载合并的配置。 We need to modify config file's content by the package that we developing so that we don't need to change config file manually after package installation.我们需要通过我们开发的 package 修改配置文件的内容,这样我们就不需要在安装 package 后手动更改配置文件。

For example, we install Laravel Horizon as a dependency the our package.例如,我们安装Laravel Horizon作为 package 的依赖项。 Horizon publishes a config file called horizon.php in app/config . Horizon 在app/config中发布了一个名为horizon.php的配置文件。 We need to auto modify some values for app/config/horizon.php before or after publishing that config file.我们需要在发布该配置文件之前或之后自动修改app/config/horizon.php的一些值。

Any help will be much appreciated.任何帮助都感激不尽。 Thanks:)谢谢:)

This is currently not possible.目前这是不可能的。 Look at Illuminate\Foundation\Console\VendorPublishCommand in the laravel framework source code.查看 laravel 框架源代码中的Illuminate\Foundation\Console\VendorPublishCommand

  1. Best way to go is to completely replace horizon.php config in your package by publishing it on the same file. go 的最佳方法是通过在同一文件上发布 package 中的 Horizo horizon.php配置来完全替换它。
  2. Alternativly you can write a custom command to inject this data in the horizon.php或者,您可以编写自定义命令将这些数据注入horizon.php
  3. You could make a PR in laravel framework for you to allow this.您可以在 laravel 框架中进行 PR 以允许您这样做。 and hope for the best they accept your PR.并希望他们接受你的 PR。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM