Skip to content

[SymfonyCache] Prevent event class from being cached by Symfony's class cache #244

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Resources/doc/features/symfony-http-cache.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,22 @@ Each feature has its subscriber. Subscribers are provided by the FOSHttpCache_
library. You can find the documentation for the subscribers in the
:ref:`FOSHttpCache Symfony Cache documentation section <foshttpcache:symfony httpcache configuration>`.

Prevent redeclaration error for Event class
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Under some circumstances this bundle loads a class which inherits from
class ``Symfony\Component\EventDispatcher\Event`` in early cache lookup phase. This
results in the following error message::

Fatal error: Cannot redeclare class Symfony\Component\EventDispatcher\Event in app/cache/dev/classes.php on line ...

This error may occur if you have told the kernel to load class cache in your
``app/console`` script, by adding something like ``$kernel->loadClassCache()``.
To get around the error you can either stop using the class cache or adding this
line to your ``app/console``::

class_exists('FOS\\HttpCache\\SymfonyCache\\CacheEvent');

directly below the inclusion of ``bootstrap.php.cache``.

.. _Symfony HttpCache documentation: http://symfony.com/doc/current/book/http_cache.html#symfony-reverse-proxy
6 changes: 6 additions & 0 deletions SymfonyCache/EventDispatchingHttpCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQ
}
}

// load `CacheEvent` class and its parent classes to prevent Symfony
// from adding them to its class cache, what results in redeclaration
// error. For more background information consult
// https://github.com/FriendsOfSymfony/FOSHttpCacheBundle/issues/242
class_exists('FOS\\HttpCache\\SymfonyCache\\CacheEvent');

return parent::handle($request, $type, $catch);
}

Expand Down