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

$event->getResult() allways null #16

Closed
dsoriano opened this issue Jul 28, 2020 · 5 comments
Closed

$event->getResult() allways null #16

dsoriano opened this issue Jul 28, 2020 · 5 comments

Comments

@dsoriano
Copy link

Hello,
I'm currently migrate a ZF2 app using BjyAuthorize and the Route Guard to Laminas.

In this app there is an API part that return JSON. In case of Unauthorized access, the app listener doesn't return a response but set a result to the dispatched event.

Actually if there is no response after trigger the error, the BjyAuthorize\Guard\Route check the event result :

        if (! $return) {
            return $event->getResult();
        }

The problem is in Laminas, trigger an event dispatch a clone of the eventPrototype :

   public function trigger($eventName, $target = null, $argv = [])
    {
        $event = clone $this->eventPrototype;
        // ...

        return $this->triggerListeners($event);
    }

So if in my listener I set a result to the event, it will be not set on the event of the BjyAuthorize\Guard\Route class but on the clone

Do you know how to deal with that ?

Thanks in advance

@dsoriano
Copy link
Author

Ok, from what I saw in Laminas MVC core code, a code update is required in BjyAuthorize\Guard\Route, replacing :

        $results = $eventManager->trigger(
            MvcEvent::EVENT_DISPATCH_ERROR,
            null,
            $event->getParams()
        );

by :

        $event->setName(MvcEvent::EVENT_DISPATCH_ERROR);
        $results = $eventManager->triggerEvent($event);

In this case the event is not cloned

@kokspflanze
Copy link
Owner

hi @dsoriano,

if you want you can do a PullRequet.

On sunday i try to check it and fix the problem, hope thats okay for you.

@dsoriano
Copy link
Author

@kokspflanze This is done, unit tests have been updated too.

@kokspflanze
Copy link
Owner

thanks, i will test my parts next days and release a new version=]

@dsoriano
Copy link
Author

Thanks ! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants