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

Add documentation for QueryBus #7

Open
fmasa opened this issue May 9, 2016 · 5 comments
Open

Add documentation for QueryBus #7

fmasa opened this issue May 9, 2016 · 5 comments
Milestone

Comments

@fmasa
Copy link
Contributor

fmasa commented May 9, 2016

No description provided.

@fmasa fmasa modified the milestones: 1.1.1, 1.1 May 9, 2016
@JanMikes
Copy link

Yeah please, im curious 😃

@fmasa
Copy link
Contributor Author

fmasa commented May 3, 2018

It's very similar to usage of command bus. The only difference is that handler returns result and that it's registered with queryBus.handler tag.

messageBus:
    queryBus:

services:
    - class: MyCoolHandler
      tags: [queryBus.handler]
class MyCoolQuery {}

class MyCoolQueryHandler
{
    public function handle(MyCoolQuery $query): string
    {
        return 'foo';
    }
}

/** @var eGen\MessageBus\Bus\QueryBus() $queryBus */
$result = $queryBus->handle(new MyCoolQuery());

// prints "foo"
print_r($result);

@JanMikes
Copy link

JanMikes commented May 10, 2018

Hi, i have found this package

I did not try it yet, but i like the usage $queryBus->handle($query, $queryResult); (the $queryResult is reference, so this variable will be created), it is similar to $queryResult = $queryBus->handle($query);

What i was excited about was, if it would be possible to pass typehint there $queryBus->handle($query, MyClass $queryResult); and IDE would know, that $queryResult will be instance of MyClass.

Right now i have to do this:

/** @var MyClass $queryResult */
$queryResult = $queryBus->handle($query);

But as i mentioned, i did not test it, so i do not even know if it is allowed to typehint references in php.

@fmasa
Copy link
Contributor Author

fmasa commented May 13, 2018

Can you post snippet of what you mean?
$queryBus->handle($query, MyClass $queryResult); is not valid PHP.

I don't really like the idea of passing reference to handle method instead of using return value. References in PHP make code hard to read and error-prone.

@JanMikes
Copy link

is not valid PHP.

Yeah, i was not sure about it, thank you for making it clear to me 👍

I must agree with you, for readability your approach is much better.

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

No branches or pull requests

2 participants