0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

symfony2.7 class not found SensioGeneratorBundle

Last updated at Posted at 2016-11-21

実行環境

  • symfony 2.7

symfony2.7を使ったプロジェクトをテストサーバーにデプロイしようとcomposer --no-dev installを実行した際
下記のエラーが発生、少しひっかかったのでメモ

PHP Fatal error:  Class 'Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle' not found in /tmp/build_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/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.

解決法

  • export SYMFONY_ENV=prod を実行する

理由

composer install --no-devで実行すると
require-devのmoduleが読み込まれません。
なのでrequire-devで読み込まれているmoduleを使用する処理が失敗します。
symfonyのインストール時の実行環境判断はSYMFONY_ENVという環境変数で行われているようで、これがない場合は開発環境devの扱いになります。
post-install-cmd時に行われているキャッシュクリアの処理の際に、AppKernel.phpが実行され、その処理の中でdevかtestの場合に読まれるもの中にrequire-devに含まれているsensio/generator-bundleが入っており
落ちる模様。

composer.phar

require-dev

    "require-dev": {
        "sensio/generator-bundle": "~2.3",
        "symfony/phpunit-bridge": "~2.7",
        "phpunit/phpunit": "3.7.*"

    },

scripts

    "scripts": {
        "post-install-cmd": [
            "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
        ],
        "post-update-cmd": [
            "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
        ]
    },

AppKernel.php

        if (in_array($this->getEnvironment(), array('dev', 'test'), true)) {
            $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
            $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
            $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
            $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
        }

最後に

  • 一応公式サイト(http://docs.symfony.gr.jp/symfony2/cookbook/deployment/tools.html) class not found出た場合はということが書いてあるけど、なんで落ちるのかが殆ど説明がなかったので調べてみた。composerとsymfonyで二重に実行環境指定しておくのはちょっと怖い。
    ローカルではオプション未指定(--dev)でインストール、SYMFONY_ENVは設定しなくてもdevなので設定を見落としても動いてしまう・・・

日本語公式からコピペ

Caution
もし “class not found” というエラーをこのステップで発生したら、 本番環境で post-install-cmd スクリプトが実行される前に export SYMFONY_ENV=prod を実行する必要があります。
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?