Chr*_*ris 8 php symfony composer-php
我的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;
}
}
Run Code Online (Sandbox Code Playgroud)
当我更新我的应用程序时,我运行php composer.phar install --no-dev --optimize-autoloader.这将安装开发环境不需要的所有要求,然后清除缓存.
但是,清除缓存失败,并显示以下消息:
PHP Fatal error: Class 'Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle' not found in /my/project/app/AppKernel.php on line 29 Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the post-install-cmd event terminated with an exception [RuntimeException] An error occurred when executing the "'cache:clear --no-warmup'" command.
这不仅是Doctrine Fixtures Bundle的一个问题.如果我更改顺序,那么Liip Functional Test Bundle会首先出现,那么错误将是关于该捆绑包的.
为什么我看到这个错误?为什么Symfony尝试访问这些捆绑包,即使我们明确没有在开发环境中(注意--no-dev作曲家标志)?如果不必在生产机器上安装所有dev依赖项,我该怎么办呢?
小智 11
这是因为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