composer是如何知道symfony环境的 [英] How does composer know symfony environment

查看:12
本文介绍了composer是如何知道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 文件?因为之后我会有一个 prod 环境,所以我不能在 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) 你应该在你的 VCS 中包含 composer.jsoncomposer.lock

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

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

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 installcomposer update 的区别(+ composer.lock):https://blog.engineyard.com/2014/composer-its-all-about-the-lock-file

difference between composer install and composer update (+ 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.ymlparameters_integ.yml 文件,其中一个文件是在部署期间自动复制到 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,这些包将不会安装在 vendor 目录中.

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-dev"键下,我定义了我不希望在生产中使用学说装置.

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 DoctrineBundleFixturesBundleDoctrineFixturesBundle();
}

如果我在生产模式下运行我的应用程序,就不会有 DoctrineFixturesBundle.

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

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

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