我的Symfony应用程序有一些依赖项,只有开发,测试等才需要.这些是在require-dev部分的composer.json中定义的.
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 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 composer标志)?如果不必在生产机器上安装所有dev依赖项,我该怎么做才能使其消失?
这是因为symfony默认env是dev,作曲家–no-dev只告诉作曲家不要安装dev要求,symfony不了解环境.
使用SYMFONY_ENV = prod环境变量.
http://symfony.com/doc/current/cookbook/deployment/tools.html#c-install-update-your-vendors
原文链接:https://www.f2er.com/php/134782.html使用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