[英]Finding the project root from within a composer package
I'm trying to provide potential locations of a config file within my package: .config.yml
我正在尝试在包中提供配置文件的潜在位置:
.config.yml
At present, I've loaded an array within one of my classes with some typical locations: 目前,我已经在一个类中的一些典型位置加载了一个数组:
protected $configDirectories = [
'./',
'./config',
'./app/config',
'./config',
'./vendor/name/packagename/config'
];
Problem is; 问题是; my package is loaded into
./vendor/name/packagename
and of course, ./
doesn't know how to get to the project root. 我的软件包已加载到
./vendor/name/packagename
,当然,。 ./
不知道如何到达项目根目录。
The aim is to allow users of this package to just drop .config.yml
into any of the pre-specified directories and it should be picked up. 目的是允许该软件包的用户将
.config.yml
放到任何预先指定的目录中,并且应该将其提取。 How can I achieve this? 我该如何实现?
I had a similar situation. 我也有类似的情况。 In my case, the front-end controller was in
./
. 就我而言,前端控制器位于
./
。 So, I required the user of my package to do something like ... 所以,我要求包裹的使用者做类似...
\Wonderful\Package\Init::setRootDirectory(__DIR__);
(But I eventually decided that instead of having magic search order happening under the covers to locate the config file, I ended up having the one (or more) config files specified explicitly (can be anywhere with any name) ... (但是我最终决定,不是让幕后的魔术搜索顺序来查找配置文件,而是让我明确指定了一个(或多个)配置文件(可以在任何位置使用任何名称)...
\Wonderful\Package\Init::loadConfigFile(__DIR__.'/config.yml');
\Wonderful\Package\Init::loadConfigFile(__DIR__.'/config.DEV-overrides.yml');
If you want to give the user the ability to configure your bundle, you MUST do it via semantic configuration and not via a specified and own config file. 如果要使用户能够配置捆绑软件,则必须通过语义配置而不是通过指定的和自己的配置文件来进行配置。 Do it the Symfony way.
以Symfony方式进行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.