Why is Symfony missing dev bundles in prod environment?(为什么 Symfony 在 prod 环境中缺少开发包?)
问题描述
我的 Symfony 应用程序有一些依赖项,这些依赖项仅用于开发、测试等.这些在我的 composer.json
的 require-dev
部分中定义.
这是我在 AppKernel.php
中添加它们的方法:
类 AppKernel 扩展内核{公共函数 registerBundles(){$bundles = 数组(新 SymfonyBundleFrameworkBundleFrameworkBundle(),新的 SymfonyBundleSecurityBundleSecurityBundle(),//...);if (in_array($this->getEnvironment(), array('dev', 'test'))) {$bundles[] = new SymfonyBundleWebProfilerBundleWebProfilerBundle();$bundles[] = 新 SensioBundleDistributionBundleSensioDistributionBundle();$bundles[] = 新 SensioBundleGeneratorBundleSensioGeneratorBundle();$bundles[] = new DoctrineBundleFixturesBundleDoctrineFixturesBundle();$bundles[] = 新的 LiipFunctionalTestBundleLiipFunctionalTestBundle();}返回 $bundles;}}
当我更新我的应用程序时,我会运行
php composer.phar install --no-dev --optimize-autoloader
.这会安装开发环境不需要的所有要求,然后清除缓存.但是,清除缓存失败并显示以下消息:
<上一页>PHP 致命错误:在第 29 行的/my/project/app/AppKernel.php 中找不到类 'DoctrineBundleFixturesBundleDoctrineFixturesBundle'脚本 SensioBundleDistributionBundleComposerScriptHandler::clearCache 处理 post-install-cmd 事件以异常终止[运行时异常]执行'cache:clear --no-warmup'"命令时出错.
这不仅仅是 Doctrine Fixtures Bundle 的问题.如果我更改顺序以便 Liip 功能测试包首先出现,那么错误将与该包有关.
为什么我会看到这个错误?为什么 Symfony 尝试访问这些包,即使我们明确不在开发环境中(注意 --no-dev
作曲家标志)?我可以做些什么来消除这种情况,而不必在生产机器上安装所有开发依赖项?
因为symfony默认的env是dev
,composer --no-dev
只告诉composer不要安装开发需求,symfony 不知道环境.使用 SYMFONY_ENV=prod
环境变量.http://symfony.com/doc/current/cookbook/deployment/tools.html#c-install-update-your-vendors
例如:$ SYMFONY_ENV=prod php composer.phar install --no-dev --optimize-autoloader
My Symfony application has a few dependencies that are only required for development, testing and the like. These are defined in my composer.json
in the require-dev
section.
Here is how I add them in AppKernel.php
:
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
new SymfonyBundleFrameworkBundleFrameworkBundle(),
new SymfonyBundleSecurityBundleSecurityBundle(),
// ...
);
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
$bundles[] = new SymfonyBundleWebProfilerBundleWebProfilerBundle();
$bundles[] = new SensioBundleDistributionBundleSensioDistributionBundle();
$bundles[] = new SensioBundleGeneratorBundleSensioGeneratorBundle();
$bundles[] = new DoctrineBundleFixturesBundleDoctrineFixturesBundle();
$bundles[] = new LiipFunctionalTestBundleLiipFunctionalTestBundle();
}
return $bundles;
}
}
When I update my application, I run php composer.phar install --no-dev --optimize-autoloader
. This installs all requirements not required for the dev environment and then clears the cache.
However, clearing the cache fails with the following message:
PHP Fatal error: Class 'DoctrineBundleFixturesBundleDoctrineFixturesBundle' not found in /my/project/app/AppKernel.php on line 29 Script SensioBundleDistributionBundleComposerScriptHandler::clearCache handling the post-install-cmd event terminated with an exception [RuntimeException] An error occurred when executing the "'cache:clear --no-warmup'" command.
This is not only a problem with the Doctrine Fixtures Bundle. If I change the order so the Liip Functional Test Bundle comes first then the error will be about that bundle.
Why am I seeing this error? Why does Symfony try to access these bundles even though we are explicitly not in the dev environment (notice the --no-dev
composer flag)? And what can I do to make this go away without having to install all dev dependencies on the production machine?
It is because symfony default env is dev
, composer --no-dev
only tells composer not to install dev requirements, symfony does not know about the environment.
Use SYMFONY_ENV=prod
environmental variable.
http://symfony.com/doc/current/cookbook/deployment/tools.html#c-install-update-your-vendors
E.g:
$ SYMFONY_ENV=prod php composer.phar install --no-dev --optimize-autoloader
这篇关于为什么 Symfony 在 prod 环境中缺少开发包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么 Symfony 在 prod 环境中缺少开发包?
基础教程推荐
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 在多维数组中查找最大值 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01