-
Notifications
You must be signed in to change notification settings - Fork 15
Invalid attaching of the ConsoleResponseSender listener #12
Comments
@fedys I think you're mis-diagnosing the root cause. The Note: I'm not saying the problem doesn't exist; I'm saying that the diagnosis is likely incorrect. I'll see if I can resolve it shortly. |
@weierophinney The problem I described really exists. The root cause is |
The problem is in zend-mvc's
The solution will be to provide a factory for the You can test this locally in the meantime. Create a factory class as follows, in namespace Application;
use Interop\Container\ContainerInterface;
use Zend\Mvc\SendResponseListener;
class SendResponseListenerFactory
{
public function __invoke(ContainerInterface $container)
{
$listener = new SendResponseListener();
$listener->setEventManager($container->get('EventManager'));
return $listener;
}
} Add the following to 'service_manager' => [
'factories' => [
\Zend\Mvc\SendResponseListener::class => \Application\SendResponseListenerFactory::class,
]
] In addition to the above, I tested by adding a single console route, and adding console usage via the I'll get a PR ready for zend-mvc shortly, and tag this and other related issues when it's ready to merge. |
Reported in: - zendframework/zend-mvc-console#10 - zendframework/zend-mvc-console#11 - zendframework/zend-mvc-console#12 The `SendResponseListener` was lazy-instantiating an event manager on first request to `getEventManager()`. However, because initializers run after delegators, this meant that the EM instance composed did not have a shared EM instance, which triggered the initializer to re-inject, losing any listeners injected by delegators. This patch introduces a factory for the `SendResponseListener`. The factory creates the instance, and then injects it with an EM instance pulled from the container; since these are guaranteed to have a shared EM instance, the initializer will skip injection, keeping any listeners injected by delegators.
Reported in: - zendframework/zend-mvc-console#10 - zendframework/zend-mvc-console#11 - zendframework/zend-mvc-console#12 The `SendResponseListener` was lazy-instantiating an event manager on first request to `getEventManager()`. However, because initializers run after delegators, this meant that the EM instance composed did not have a shared EM instance, which triggered the initializer to re-inject, losing any listeners injected by delegators. This patch introduces a factory for the `SendResponseListener`. The factory creates the instance, and then injects it with an EM instance pulled from the container; since these are guaranteed to have a shared EM instance, the initializer will skip injection, keeping any listeners injected by delegators.
To get the fix, please update your zend-mvc to 3.0.3: $ composer require "zendframework/zend-mvc:^3.0.3" |
Updates the test written for #11, and modifies it as follows: - Uses the new `SendResponseListenerFactory` to create the `SendResponseListener` instance. - Registers the `ConsoleResponseSenderDelegatorFactory` directly in the test setup, instead of wrapping it in a callable; we're only interested in the final state of the event manager. - Updates the minimum zend-mvc requirement to 3.0.3, which introduces the `SendResponseListenerFactory`.
This issue is related to the #10
Because of the ConsoleResponseSender is attached via the delegator and delegators are called before initializers then the EventManagerAwareInitializer (re)sets the EventManager which causes lost of all previously attached listeners including the ConsoleResponseSender.
The text was updated successfully, but these errors were encountered: