Skip to content

Commit 90bed43

Browse files
committed
Merge pull request #249 from FriendsOfSymfony/workaround-classcache
work around to avoid problems with the HttpKernel::loadClassCache mechanism
2 parents 006c2b6 + 8b90c5c commit 90bed43

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

doc/symfony-cache-configuration.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ When starting to extend your ``AppCache``, it is recommended to use the
6363
``EventDispatchingHttpCacheTestCase`` to run tests with your kernel to be sure
6464
all events are triggered as expected.
6565

66+
.. note::
67+
68+
If you use ``HttpKernel::loadClassCache`` from the console, you will need
69+
to add ``class_exists('FOS\\HttpCache\\SymfonyCache\\CacheEvent');`` right
70+
after the inclusion of ``bootstrap.php.cache`` in ``app/console``. For web
71+
requests, this is done automatically by the trait. If you miss to do so,
72+
you will get the following error:
73+
74+
.. code-block:: bash
75+
76+
Fatal error: Cannot redeclare class Symfony\Component\EventDispatcher\Event in app/cache/dev/classes.php on line ...
77+
6678
Cache event listeners
6779
~~~~~~~~~~~~~~~~~~~~~
6880

src/SymfonyCache/EventDispatchingHttpCache.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ public function addSubscriber(EventSubscriberInterface $subscriber)
7878
*/
7979
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
8080
{
81+
// trigger loading the CacheEvent to avoid fatal error when HttpKernel::loadClassCache is used.
82+
class_exists('FOS\\HttpCache\\SymfonyCache\\CacheEvent');
83+
8184
if ($response = $this->dispatch(Events::PRE_HANDLE, $request)) {
8285
return $this->dispatch(Events::POST_HANDLE, $request, $response);
8386
}

0 commit comments

Comments
 (0)