Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 更改Symfony2项目的默认配置文件 上下文_Php_Symfony_Command - Fatal编程技术网

Php 更改Symfony2项目的默认配置文件 上下文

Php 更改Symfony2项目的默认配置文件 上下文,php,symfony,command,Php,Symfony,Command,我有一个简单的Symfony2项目(仅限于命令行命令)。此项目包括一个app/config.yml文件,其中包含用于创建依赖项注入的信息 例如,app/config.yml包含: github: token: abcdefgh services: github.client: class: Github\Client calls: - ['authenticate', [%github.token%, null, 'htt

我有一个简单的Symfony2项目(仅限于命令行命令)。此项目包括一个
app/config.yml
文件,其中包含用于创建依赖项注入的信息

例如,
app/config.yml
包含:

github:
    token: abcdefgh
services:
    github.client:
        class: Github\Client
        calls:
            - ['authenticate', [%github.token%, null, 'http_token']]
src/Foo/Resources/config/github.yml
(服务文件)包含:

github:
    token: abcdefgh
services:
    github.client:
        class: Github\Client
        calls:
            - ['authenticate', [%github.token%, null, 'http_token']]
文件
app/config.yml
Application::\u construct()
函数加载

当我运行
app/console mycommand
时,它使用定义的令牌

需要 我需要能够使用不同的配置运行我的命令。 现在,我手动替换
app/config.yml
文件,但它很糟糕

为此,我考虑了两种可能的解决方案:

  • 当我运行
    app/console mycommand--f=app/config2.yml
    时,能够指定另一个
    app/config.yml
    文件
  • 拥有另一个用于特定命令用法的配置文件,并将其与
    app/console mycommand--f=myconfig.yml
    一起使用。问题是依赖项注入在应用程序运行后无法工作或更新

我不知道如何做这个解决方案中的一个(或者第三个,没关系)。如果这是一种常见的行为,你能给我一些文档或示例来做类似的事情吗?

完全可以使用不同的环境,请查看文档:


通常,您将使用--env=myenv指定环境。

这看起来是个好问题,但请不要添加元注释。我现在暂停我的规则,即要求不要投反对票的问题立即得到一张!嗨,内森!谢谢你的回答。改变环境看起来是一个小的解决办法,但这给了我一个想法。我刚刚更新了我的应用程序,添加了一个新选项来更改配置文件。事实上,我在这个应用程序中没有任何内核。哦,我明白了。那么,你需要更多的信息还是可以?