我的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事件,异常终止 [RuntimeException] 执行“'cache:clear --no-warmup'”命令时发生错误。
这不仅是教义治具包的问题。如果我更改顺序,那么Liip Functional Test Bundle首先出现,那么错误将出在那个包上。
为什么会看到此错误?即使我们明确不在开发环境中,Symfony为什么也尝试访问这些捆绑软件(请注意--no-dev
composer标志)?而我该如何做而不必在生产计算机上安装所有开发依赖项呢?
这是因为symfony默认的env是dev
,composer --no-dev
仅告诉作曲家不安装dev要求,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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句