为什么Symfony在产品环境中会丢失开发包? [英] Why is Symfony missing dev bundles in prod environment?

查看:42
本文介绍了为什么Symfony在产品环境中会丢失开发包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Symfony应用程序具有一些依赖关系,这些依赖关系仅在开发,测试等过程中才需要。这些在我的 composer.json 中的 require-dev 部分中定义。

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.

这是我在 AppKernel.php 中添加它们的方式:

Here is how I add them in 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 。这将安装开发环境不需要的所有要求,然后清除缓存。

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 '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.

这不仅仅是教义治具捆绑包的问题。如果我更改顺序以使Liip Functional Test Bundle首先出现,那么该错误将与该软件包有关。

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.

为什么我会看到此错误?即使我们明确不在开发环境中,Symfony为什么也尝试访问这些捆绑软件(请注意-no-dev composer标志)?而我该怎么做而不必在生产计算机上安装所有dev依赖项呢?

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?

推荐答案

这是因为symfony的默认环境是 dev composer --no-dev 仅告诉作曲家不要安装开发需求,symfony不会了解环境。
使用 SYMFONY_ENV = prod 环境变量。
http:// symfony .com / doc / current / cookbook / deployment / tools.html#c-install-update-your-vendors

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

例如:
$ SYMFONY_ENV = prod php composer.phar install --no-dev --optimize-autoloader

这篇关于为什么Symfony在产品环境中会丢失开发包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆