作曲家如何知道Symfony环境 [英] How does composer know symfony environment

查看:73
本文介绍了作曲家如何知道Symfony环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在集成环境中部署应用程序,但是在 composer update命令之后,生成的parameters.yml文件不包含可能的集成参数

i try to deploy an app in "integration" environment but after the "composer update" command, the parameters.yml file generated doesn't contains may integration parameters

这就是我的工作:
我在app / config中使用以下命令创建了一个 config_integ.yml文件:

Here is what i did : I created a "config_integ.yml" file in app/config with :

# app/config/config_integ.yml
imports:
    - { resource: parameters_integ.yml }
    - { resource: config.yml }

framework:
    profiler: { only_exceptions: false }

parameters_integ.yml文件包含用于集成环境的参数。开始的示例:

the parameters_integ.yml file contains parameters for integration environment. example of the beggining :

parameters:
    database_host: localhost
    database_port: null
    database_name: test_integ
    database_user: root

parameters.yml.dist包含这些参数的默认值:

the parameters.yml.dist contains these parameters with default values :

parameters:
    database_host:     127.0.0.1
    database_port:     ~
    database_name:     symfony
    database_user:     root

我如何告诉作曲家使用parameters_integ.yml文件建立parameter.yml文件?因为之后我将拥有一个产品环境,所以我无法在parameters.yml.dist文件中写入参数。

How can i tell to composer to take the parameters_integ.yml file to build the parameter.yml file ? Because i will have a prod environment after, i can't write my parameters in parameters.yml.dist file.

如果需要其他信息,请告诉我

Tell me if you need other informations

感谢您的帮助

推荐答案

1)您应该包括 composer。 中的json 和 composer.lock

1) You should include composer.json and composer.lock in your VCS

2)您不应包含 parameters.yml 在您的VCS中

2) You should not include parameters.yml in your VCS

3)部署Sf应用程序时,应使用 composer install

3) When deploying Sf application you should use composer install

composer安装和 composer更新(+ composer.lock ): https://blog.engineyard.com/2014/composer-its-all-about-the-lock-file

4)我可以想到几种在集成环境中创建 parameters.yml 的方法:

4) I can think of a few ways for creating parameters.yml in the integration environment:


  • 您手动创建 parameters.yml 文件并将其放置在 parameters.dist.yml

  • you manually create parameters.yml file and place it beside parameters.dist.yml


  • 如果没有 parameters.yml parameters.yml 缺少一些参数,当您运行 composer install 时,系统将提示您输入缺少的参数,并且将创建/更新 parameters.yml 。在 composer安装过程中

  • if there is no parameters.yml or parameters.yml has some missing parameters, when you run composer install, you will be prompted to enter missing parameters and parameters.yml will be created/updated during the composer install process


  • 您可以拥有一个 app / config / parameters 文件夹,其中包含 parameters_prod.yml parameters_integ.yml 文件,以及这些文件之一是aut在部署过程中自动复制到 parameter.yml 文件中(最复杂的解决方案)

  • you can have an app/config/parameters folder containing parameters_prod.yml and parameters_integ.yml files, and one of those files is automatically copied into parameter.yml file during deployment (most complicated solution)

如果要通过浏览器访问集成环境,还应该为其创建前端控制器。将 web / app.php 文件复制到 web / app_integ.php 并编辑要集成的环境:

If you want integration environment to be accessible via a browser, you should also create a front controller for it. Copy the web/app.php file to web/app_integ.php and edit the environment to be integration:

// web/app_integ.php
// ...

// change just this line
$kernel = new AppKernel('integ', false);

// ...

https://symfony.com/doc/current/configuration/environments.html #creating-a-new-environment

标题标题为如何作曲家知道symfony环境吗?-我认为作曲家对Sf环境一无所知:)

And the answer to the question from the title, "How does composer know symfony environment" - I think composer has no idea about Sf environment :)

作曲家具有 require-dev 选项,用于生产中不需要的软件包,运行测试所需的软件包(例如phpunit),开发过程中的一些调试内容等。
例如,这就是我的 composer.json 文件如下:

The composer has require-dev option for packages that you do not need in your production, packages required for running tests (phpunit for example), some debugging stuff during development, etc. For an example this is how one of my composer.json files looks like:

...
"require-dev": {
    "sensio/generator-bundle": "^3.0",
    "symfony/phpunit-bridge": "^3.0",
    "doctrine/doctrine-fixtures-bundle": "^2.3",
    "nelmio/alice": "^2.1",
    "deployer/deployer": "^4.0"
},
...

如果我运行 composer install --no-dev ,这些软件包不会

If I run composer install --no-dev, these packages won't be installed in the vendor directory.

但是,Sf如何知道何时在应用程序中包括/省略某些软件包。

But, how Sf knows when to include/omit some packages in the app.

AppKernel.php 内部定义。

composer.json 中的 require-开发人员键,我定义我不想在生产环境中使用教义装置。

In the composer.json, under "require-dev" key I defined that I don't want doctrine fixtures in production.

因此,在 AppKernel.php 中,我放置了以下代码行:

So, inside AppKernel.php I put these lines of code:

if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
    ...
    $bundles[] = new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle();
}

如果我在生产模式下运行应用程序,将没有DoctrineFixturesBundle。

And if I run my app in production mode, there will not be DoctrineFixturesBundle.

这篇关于作曲家如何知道Symfony环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆