-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[2.x] Cannot redeclare class #96
Comments
I guess it's related to symfony/symfony#7360. |
+1 |
Could someone reproduce this on a fresh fork of the symfony-standard edition version 2.1? |
When I have controller action with @secure annotation and I'm trying to clear cache for prod env (cache folder is empty - no files inside) this exception appears. |
I just tried upgrading again, from Symfony 2.1.8 to 2.1.9, but this error is still present using
Would be nice to have this fixed soon. |
same here. It was giving an error since several days ago. I've added "minimum-stability": "dev" and now works. So maybe it's fixed.
|
I tried again using the following sets with Symfony 2.1.9:
Both don't work. |
Christian, are you using Twig? I've just found out that if I do:
if I have loaded Twig in AppKernel I have this error:
if I haven't loaded Twig then I have the redeclare error:
Totally blocked right now :S. |
@fesja: Yes, I'm using Twig. But I don't think that it has to do with this issue directly. I have no idea which component is causing it, though. @schmittjoh: Can you reproduce it? |
@craue you'll see the root cause of this bug in the PR link above. I think the fix is on Sf2 side. |
It happens in my case is that if I do: ...
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Component\HttpFoundation\Request;
use JMS\SecurityExtraBundle\Annotation\Secure;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
/**
*
*/
class OrganizationController extends Controller
{
/**
* @Route("/organizations/new")
* @Method({"GET","POST"})
* @Secure(roles="ROLE_ORG_ADMIN")
*/
public function newAction(Request $request)
{ instead of ...
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Component\HttpFoundation\Request;
use JMS\SecurityExtraBundle\Annotation\Secure;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
/**
*
*/
class OrganizationController extends Controller
{
/**
* @Route("/organizations/new")
* @Method({"GET","POST"})
* @Secure(roles="ROLE_ORG_ADMIN")
*/
public function newAction(Request $request)
{ It works ! See the different ? there is an extra return between this line use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; and the comment block /**
*
*/
class OrganizationController extends Controller |
In my case, |
@schmittjoh: Here's how to trigger this error with a clean 2.1.9 standard edition: In /**
* @Route("/hello/admin/{name}", name="_demo_secured_hello_admin")
* @Secure(roles="ROLE_ADMIN")
* @Template()
*/
public function helloadminAction($name)
{
return array('name' => $name);
} from public function helloadminAction($name)
{ to public function helloadminAction($name) { and try clearing the cache with |
What is the status of this ticket? |
Any updates to this? |
I just stumbled into this bug when upgrading to 2.3 but then even downgrading to 2.2 results in the same error. |
I discovered if I remove the cache folder manually (rm -Rf) and then visit a URL with a controller using a JMS bundle (in this case, the JMS Security for a @secure annotation) everything works as expected, in this case, if I go and do a cache:clear I get no errors (with or without warmup). A bit annoying but at least that works. |
+1 |
+1 here, |
+1 |
MacOS without APC:
Running cache:clear a second time works unless cache doesn't exist, e.g.,
|
This code seems related (in
This probably needs to be adjusted to detect the 2.3 way of naming the temporary cache directory ( EDIT: Tested and working with this replacement code:
|
Unfortunately, the workaround from @tomat doesn't work for me in symfony 2.3 :/ |
Yeah, just noticed that this bug was older than Symfony 2.3, but my PR will solve it for some users at least. @swis: Do you have an updated |
…(and v2.3.1 with JMSDiExtraBundle and JMSSecurityExtraBundle dependencies restored)
…(and v2.3.1 with JMSDiExtraBundle and JMSSecurityExtraBundle dependencies restored)
Same problem found in symfony 2.1.11. PHP Fatal error: Cannot redeclare class EnhancedProxy_ed2f3cb92db5d961490e60a593d20b156b460b0d__CG__\MV\CaravanBundle\Controller\AdminLogController in app/cache/pro_/jms_diextra/proxies/MV-CaravanBundle-Controller-AdminLogController.php on line 37 |
Check out this PR, was very helpful for me |
+1 |
@i4got10 Could not test #131 with the cache:clear command as it is broken in my project now but it does not solve the issue when refreshing a page @vkhramtsov : same thing |
I'm having this issue as well with Symfony 2.3. Could it be as I use my controller as a service? |
The bad part with this bug is that
After more than 12 hours I stumbled on same issues as listed before. I see no option now than leaving all these bundles behind and probably get back and contribute with ideas if by that time it won't be fixed. |
I was already wondering why I'd need 3 bundles just to be able to add an @secure to my action... Some other things I've noticed while developing with this bundle:
|
@CristianSitov in our project the bundles causes issues in dev environnement and cache clearing but it has no impact in our production, everything works fine and as expected, maybe you don't have to leave the bundles ... @iltar That's called decoupling ! yes you need several bundle for the @secure annotation but you may not need the whole security bundle if you're only looking at AOP capabilities, etc ... the "hard" refresh or "smooth" refresh makes no difference server side (it's only a matter of browser caching) |
@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. |
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 |
@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} $
|
I think the best solution would be what I've written in a comment above, |
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 ... |
That's my problem exactly, I get this error after a page refresh. |
Ah, that's interesting. Then, we are talking about different errors here. Maybe we need to implement a similar strategy as the DoctrineBundle: |
The 2 errors leeds to the same exception message: cannot redeclare class etc ... see #96 (comment) 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 |
Could you check whether the workaround in #131 fixes these issues for you? If so, I'll merge that. |
not fixing the issue on page refresh |
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 |
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 ... |
Still getting this issue with symfony 2.4.6, jms/di-extra-bundle 1.4.0 |
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 ;-)). |
I have the same error with 2.3.18 Any thoughts? |
I had the same problem. The warmup can be called as a separate command if needed. |
Same issue for us: 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 |
We had the same issue, and for us the solution from @Metabor also worked. |
We have the same issue when upgrading from symfony 2.3 to 2.8 |
I just added some ACL stuff to my project and now, when clearing the cache with
immediately I got the following error:
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:
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).The text was updated successfully, but these errors were encountered: