schmittjoh / JMSDiExtraBundle

Provides Advanced Dependency Injection Features for Symfony2
http://jmsyst.com/bundles/JMSDiExtraBundle
330 stars 130 forks source link

[2.x] Cannot redeclare class #96

Open swis opened 11 years ago

swis commented 11 years ago

I just added some ACL stuff to my project and now, when clearing the cache with

php app/console cache:clear --env=dev_frontend

immediately I got the following error:

PHP Fatal error:  Cannot redeclare class EnhancedProxy_bc38afde4093145355d8d5cbefd3edaa1f79fdce\__CG__\Acme\Bundle\BlogBundle\Controller\BackendController in /var/www/myProject/app/cache/dev_fronten_/jms_diextra/proxies/Acme-Bundle-BlogBundle-Controller-BackendController.php on line 55
PHP Stack trace:
PHP   1. {main}() /var/www/myProject/app/console:0
PHP   2. Symfony\Component\Console\Application->run() /var/www/myProject/app/console:22
PHP   3. Symfony\Bundle\FrameworkBundle\Console\Application->doRun() /var/www/myProject/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:106
PHP   4. Symfony\Component\Console\Application->doRun() /var/www/myProject/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:78
PHP   5. Symfony\Component\Console\Command\Command->run() /var/www/myProject/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:193
PHP   6. Symfony\Bundle\FrameworkBundle\Command\CacheClearCommand->execute() /var/www/myProject/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:240
PHP   7. Symfony\Bundle\FrameworkBundle\Command\CacheClearCommand->warmup() /var/www/myProject/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php:83
PHP   8. Symfony\Component\HttpKernel\Kernel->boot() /var/www/myProject/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php:110
PHP   9. Symfony\Component\HttpKernel\Kernel->initializeContainer() /var/www/myProject/app/bootstrap.php.cache:378
PHP  10. Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate->warmUp() /var/www/myProject/app/bootstrap.php.cache:601
PHP  11. JMS\DiExtraBundle\HttpKernel\ControllerInjectorsWarmer->warmUp() /var/www/myProject/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php:47
PHP  12. JMS\DiExtraBundle\HttpKernel\ControllerResolver->createInjector() /var/www/myProject/vendor/jms/di-extra-bundle/JMS/DiExtraBundle/HttpKernel/ControllerInjectorsWarmer.php:37 
PHP  13. JMS\DiExtraBundle\HttpKernel\ControllerResolver->prepareContainer() /var/www/myProject/vendor/jms/di-extra-bundle/JMS/DiExtraBundle/HttpKernel/ControllerResolver.php:98
PHP  14. JMS\DiExtraBundle\Generator\DefinitionInjectorGenerator->generate() /var/www/myProject/vendor/jms/di-extra-bundle/JMS/DiExtraBundle/HttpKernel/ControllerResolver.php:157

I already tried different versions of Symfony and DiExtraBundle (and different combinations), but the error remains even when I downgrade Symfony to 2.1. I don't know, but I suppose, this is somehow related to #95 - especially because of this CacheWarmer issue in the Stack. But I'm pretty sure, to not compile any Controller manually. Here's my current composer.json:

{
    "name": "symfony/framework-standard-edition",
    "description": "The \"Symfony Standard Edition\" distribution",
    "autoload": {
        "psr-0": { "": "src/" }
    },
    "require": {
        "php": ">=5.3.3",
        "symfony/symfony": "2.2.*",
        "doctrine/orm": "2.3.*",
        "doctrine/doctrine-bundle": "*",
        "twig/extensions": "1.0.*",
        "symfony/assetic-bundle": "2.1.*",
        "symfony/swiftmailer-bundle": "2.2.*",
        "symfony/monolog-bundle": "2.2.*",
        "sensio/distribution-bundle": "2.2.*",
        "sensio/framework-extra-bundle": "2.2.*",
        "sensio/generator-bundle": "2.2.*",
        "jms/security-extra-bundle": "dev-master",

        "mopa/bootstrap-bundle": "dev-master",
        "twitter/bootstrap": "v2.2.2",

        "sonata-project/block-bundle": "*",

        "dannytrue/phpthumb": "dev-master",
        "stof/doctrine-extensions-bundle": "dev-master",
        "doctrine/doctrine-fixtures-bundle": "dev-master",
        "doctrine/doctrine-migrations-bundle": "dev-master",
        "friendsofsymfony/user-bundle": "dev-master",
        "knplabs/knp-menu-bundle":"dev-master",
        "knplabs/knp-paginator-bundle": "dev-master",
        "stfalcon/tinymce-bundle": "dev-master"
    },
    "scripts": {
        "post-install-cmd": [
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Acme\\Bundle\\LogicBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
            "Mopa\\Bundle\\BootstrapBundle\\Composer\\ScriptHandler::postInstallSymlinkTwitterBootstrap"
        ],
        "post-update-cmd": [
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Acme\\Bundle\\LogicBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
            "Mopa\\Bundle\\BootstrapBundle\\Composer\\ScriptHandler::postInstallSymlinkTwitterBootstrap"
        ]
    },
    "minimum-stability": "dev",
    "extra": {
        "symfony-app-dir": "app",
        "symfony-web-dir": "web",
        "symfony-assets-install": "symlink"
    }
}

I'm looking for a workaround, since clearing the cache manually by removing the files is not appropriate in my case (especially for the CI stuff).

It may be of note that I'm using @SecureParam as well as @Secure annotations (the error occurs even if I use only one of them in the BackendController).

linaori commented 10 years ago

@tkleinhakisa More code means more chances of bugs. More code also means longer execution times (generally speaking). I do not wish to have 3 bundles just to add an @Secure to my page. Sadly, this forces me to use these 3 bundles. I guess the only way to fix this is to write a custom bundle.

tkleinhakisa commented 10 years ago

Anyway that's not the point here ...

@schmittjoh From what i've learned so far digging into this issue, one solution would be to have the proxy classes autoloaded so the problematic "require_once" statements could be removed. Any help on this would be greatly appreciated, some hints about where to start, or just a feedback on "do-ability"

Maybe as first step we should create a clean standard-edition fork with a minimal setup to reproduce the issue

CristianSitov commented 10 years ago

@tkleinhakisa I did not drop the bundles; instead I've added a post-install command which removes the unit-tests from that bundle, so now everything works smooth.

However, just so you know, for me Production has same issue as Dev:

l(esoh@cristi-vm)-(02:22 PM Mon Nov 18)-(/var/www/)-(13 files, 1.1Mb) | {feature/i18n} $

./app/console cache:clear --env=prod Clearing the cache for the prod environment with debug false PHP Fatal error: Cannot redeclare class EnhancedProxy73b88e6bf5989f9e4785cea753cad509a15376f1CG\JMS\SecurityExtraBundle\Tests\Functional\TestBundle\Controller\PostController in /var/www/app/cache/pro/jms_diextra/lookup_method_classes/JMS-SecurityExtraBundle-Tests-Functional-TestBundle-Controller-PostController.php on line 11 l(esoh@cristi-vm)-(02:22 PM Mon Nov 18)-(/var/www/)-(13 files, 1.1Mb) | {feature/i18n} $

schmittjoh commented 10 years ago

I think the best solution would be what I've written in a comment above, https://github.com/schmittjoh/JMSDiExtraBundle/issues/96#issuecomment-21028440

tkleinhakisa commented 10 years ago

I think that adding a command to invoke manualy is not an option ... what about the case when you get the error after refreshing a page in the browser ? should i run the additionnal command every time i make a change in my controller ? maybe i missed something ...

linaori commented 10 years ago

That's my problem exactly, I get this error after a page refresh.

schmittjoh commented 10 years ago

Ah, that's interesting. Then, we are talking about different errors here.

Maybe we need to implement a similar strategy as the DoctrineBundle: https://github.com/doctrine/DoctrineBundle/blob/master/DoctrineBundle.php#L101

tkleinhakisa commented 10 years ago

The 2 errors leeds to the same exception message: cannot redeclare class etc ... see https://github.com/schmittjoh/JMSDiExtraBundle/issues/96#issuecomment-24142354

They append in different places but the error is caused by the "require" statements ... so having autoloading for the proxies would solve both cases, so yes a strategy like doctrine would solve the problem i think

schmittjoh commented 10 years ago

Could you check whether the workaround in #131 fixes these issues for you? If so, I'll merge that.

tkleinhakisa commented 10 years ago

@schmittjoh see https://github.com/schmittjoh/JMSDiExtraBundle/issues/96#issuecomment-28063266

not fixing the issue on page refresh

walva commented 10 years ago

I had this problem today while installing JMSTranslationBundle UI... was going crazzy because I really needed this feature for a prod project. When deleting the cache folder or executing cache:clear, was getting the error. In fact, I was keeping a copy of one of my controller with the sufix "2Controller". When I deleted it, everything were working fine !

tkleinhakisa commented 10 years ago

The issue seems to have been fixed in a way or another ... i didn't get that error for a longtime now in dev ... should make some further test to be sure ...

thomasrose commented 10 years ago

Still getting this issue with symfony 2.4.6, jms/di-extra-bundle 1.4.0

luebbert42 commented 10 years ago

I have the same (?) error using jms/di-extra-bundle dev-master in combination with Symfony 2.5.2 and "coresphere/console-bundle" - I am trying to run the clear cache command from the browser (don't ask why ;-)).

ZCJ commented 10 years ago

I have the same error with 2.3.18 I am unable to reproduce what I have added to my code. If I run cache:clear twice, I get the error ... If I run cache:clear after cache:warmup ... it works fine (which is expected) ... I am using: "jms/security-extra-bundle": "~1.5",

Any thoughts?

Metabor commented 9 years ago

I had the same problem. What worked for us was removing the automatic warmup from the clear command: app/console cache:clear --no-warmup --no-optional-warmers

The warmup can be called as a separate command if needed.

mmeloni commented 9 years ago

Same issue for us: we have Cannot redeclare class EnhancedProxy73b88e6bf5989f9e4785cea753cad509a15376f1CG\JMS\SecurityExtraBundle\Tests\Functional\TestBundle\Controller\PostController in /mnt/www/nextop/releases/20150422071136/app/cache/pro/jms_diextra/lookup_method_classes/JMS-SecurityExtraBundle-Tests-Functional-TestBundle-Controller-PostController.php on line 11 [2015-04-22 09:26:18] php.EMERGENCY: Fatal Compile Error: Cannot redeclare class EnhancedProxy73b88e6bf5989f9e4785cea753cad509a15376f1CG\JMS\SecurityExtraBundle\Tests\Functional\TestBundle\Controller\PostController {"type":1,"file":"/mnt/www/nextop/releases/20150422071136/app/cache/pro/jms_diextra/lookup_method_classes/JMS-SecurityExtraBundle-Tests-Functional-TestBundle-Controller-PostController.php","line":11,"level":6143,"stack":[]}

2015/04/22 07:08:28 [error] 7766#0: *91117 FastCGI sent in stderr: "PHP message: PHP Warning: require_once(/mnt/www/nextop/releases/20150421142932/app/cache/prod/jms_diextra/doctrine/EntityManager_55365f87a155a.php): failed to open stream: No such file or directory in /mnt/www/nextop/releases/20150421142932/app/cache/prod/appProdProjectContainer.php on line 1288 PHP message: PHP Fatal error: require_once(): Failed opening required '/mnt/www/nextop/releases/20150421142932/app/cache/prod/jms_diextra/doctrine/EntityManager_55365f87a155a.php' (include_path='/mnt/www/nextop/releases/20150421142932/vendor/phpunit/php-text-template:/mnt/www/nextop/releases/20150421142932/vendor/phpunit/php-timer:.:/usr/share/php:/usr/share/pear') in /mnt/www/nextop/releases/20150421142932/app/cache/prod/appProdProjectContainer.php on line 1288" while reading response header from upstream, client: 172.31.16.102, server: www.xxx.it, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.xxx.it"

sabinequ commented 9 years ago

We had the same issue, and for us the solution from @Metabor also worked.

wangdong2023 commented 8 years ago

We have the same issue when upgrading from symfony 2.3 to 2.8