Skip to content
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

Bug in OnEventStrategy #169

Closed
prolic opened this issue Oct 21, 2017 · 0 comments · Fixed by #171
Closed

Bug in OnEventStrategy #169

prolic opened this issue Oct 21, 2017 · 0 comments · Fixed by #171
Assignees
Labels

Comments

@prolic
Copy link
Member

prolic commented Oct 21, 2017

<?php

require 'vendor/autoload.php';

$eventBus = new \Prooph\ServiceBus\EventBus();

$router = new \Prooph\ServiceBus\Plugin\Router\EventRouter();
$router
    ->route(\Acme\SomethingHappended::class)
    ->to(\Acme\SomethingHappendedHandler2::class)
    ->andTo(function (\Acme\SomethingHappended $event) {
        echo $event->messageName() . ' called, too';
    });

$router->attachToMessageBus($eventBus);

$container = new class implements \Psr\Container\ContainerInterface {
    public function get($id)
    {
        switch ($id) {
            case \Acme\SomethingHappendedHandler2::class:
                return new \Acme\SomethingHappendedHandler2();
                break;
        }
    }

    public function has($id)
    {
        return true;
    }
};

$onEventHandlerStrategy = new \Prooph\ServiceBus\Plugin\InvokeStrategy\OnEventStrategy();
$onEventHandlerStrategy->attachToMessageBus($eventBus);

$serviceLocatorPlugin = new \Prooph\ServiceBus\Plugin\ServiceLocatorPlugin($container);
$serviceLocatorPlugin->attachToMessageBus($eventBus);

$eventBus->dispatch(new \Acme\SomethingHappended(['1' => '2']));

output:

array(1) {
  [1]=>
  string(1) "2"
}
PHP Fatal error:  Uncaught Error: Call to undefined method Closure::onEvent() in /home/sasa/code/service-bus-demo/vendor/prooph/service-bus/src/Plugin/InvokeStrategy/OnEventStrategy.php:35

Second problem: This strategy has to be attached with higher priority.

@prolic prolic added the bug label Oct 21, 2017
@prolic prolic self-assigned this Oct 21, 2017
prolic added a commit that referenced this issue Oct 22, 2017
prolic added a commit that referenced this issue Oct 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant