【发布时间】:2015-05-18 16:59:17
【问题描述】:
我的 Symfony 应用程序有一些依赖项,这些依赖项仅用于开发、测试等。这些在我的composer.json require-dev 部分中定义。
这是我在AppKernel.php 中添加它们的方法:
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
// ...
);
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
$bundles[] = new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle();
$bundles[] = new Liip\FunctionalTestBundle\LiipFunctionalTestBundle();
}
return $bundles;
}
}
当我更新我的应用程序时,我运行php composer.phar install --no-dev --optimize-autoloader。这会安装开发环境不需要的所有要求,然后清除缓存。
但是,清除缓存失败并显示以下消息:
PHP 致命错误:在第 29 行的 /my/project/app/AppKernel.php 中找不到类 'Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle' 脚本 Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache 处理 post-install-cmd 事件以异常终止 [运行时异常] 执行“'cache:clear --no-warmup'”命令时出错。这不仅仅是 Doctrine Fixtures Bundle 的问题。如果我更改顺序以便 Liip 功能测试包首先出现,那么错误将与该包有关。
为什么我会看到这个错误?为什么 Symfony 尝试访问这些包,即使我们明确不在开发环境中(注意 --no-dev composer 标志)?我可以做些什么来消除这种情况,而不必在生产机器上安装所有开发依赖项?
【问题讨论】:
标签: php symfony composer-php