加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 为什么Symfony在prod环境中缺少dev bundle?

发布时间:2020-12-13 18:09:43 所属栏目:PHP教程 来源:网络整理
导读:我的Symfony应用程序有一些依赖项,只有开发,测试等才需要.这些是在require-dev部分的composer.json中定义的. 以下是我在AppKernel.php中添加它们的方法: class AppKernel extends Kernel{ public function registerBundles() { $bundles = array( new Symfo
我的Symfony应用程序有一些依赖项,只有开发,测试等才需要.这些是在require-dev部分的composer.json中定义的.

以下是我在AppKernel.php中添加它们的方法:

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            new SymfonyBundleFrameworkBundleFrameworkBundle(),new SymfonyBundleSecurityBundleSecurityBundle(),// ...
        );

        if (in_array($this->getEnvironment(),array('dev','test'))) {
            $bundles[] = new SymfonyBundleWebProfilerBundleWebProfilerBundle();
            $bundles[] = new SensioBundleDistributionBundleSensioDistributionBundle();
            $bundles[] = new SensioBundleGeneratorBundleSensioGeneratorBundle();
            $bundles[] = new DoctrineBundleFixturesBundleDoctrineFixturesBundle();
            $bundles[] = new LiipFunctionalTestBundleLiipFunctionalTestBundle();
        }

        return $bundles;
    }
}

当我更新我的应用程序时,我运行php composer.phar install –no-dev –optimize-autoloader.这将安装开发环境不需要的所有要求,然后清除缓存.

但是,清除缓存失败,并显示以下消息:

PHP Fatal error:  Class 'DoctrineBundleFixturesBundleDoctrineFixturesBundle' not found in /my/project/app/AppKernel.php on line 29
Script SensioBundleDistributionBundleComposerScriptHandler::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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读