Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

HypeMC
Copy link
Member

@HypeMC HypeMC commented Dec 6, 2022

Q A
Branch? 6.2
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #48506
License MIT
Doc PR -

The #[Cache()] attribute is suppose to be a replacement for the SensioFrameworkExtraBundle @Cache annotation, but unlike the annotation, it doesn't work when entities are used in expressions. The reason for it is that the CacheAttributeListener is triggered by a kernel.controller event, while the EntityValueResolver is called afterwards:

$event = new ControllerEvent($this, $controller, $request, $type);
$this->dispatcher->dispatch($event, KernelEvents::CONTROLLER);
$controller = $event->getController();
// controller arguments
$arguments = $this->argumentResolver->getArguments($request, $controller, $event->getControllerReflector());
$event = new ControllerArgumentsEvent($this, $event, $arguments, $request, $type);
$this->dispatcher->dispatch($event, KernelEvents::CONTROLLER_ARGUMENTS);
$controller = $event->getController();

This PR attempts to solve this problem by changing the event of the CacheAttributeListener to kernel.controller_arguments. Even though this has a BC break the listener was introduced in 6.2 so it might still be early enough to make this change? In any case, I don't have a better idea how to fix this, so I'm open to suggestions.

@fabpot
Copy link
Member

fabpot commented Dec 6, 2022

Thank you @HypeMC.

@fabpot fabpot merged commit 7d45767 into symfony:6.2 Dec 6, 2022
@HypeMC HypeMC deleted the cache-attribute-fix branch December 6, 2022 17:07
@fabpot fabpot mentioned this pull request Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants