Skip to content

Commit

Permalink
add register specification query handler guide
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-gribanov committed Jun 16, 2017
1 parent 01365e7 commit aa3be63
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ composer require gpslab/specification-query
You can use Specifications as a simple query.

```php
use GpsLab\Component\Query\Bus\HandlerLocatedQueryBus;
use GpsLab\Component\Query\Handler\Locator\DirectBindingQueryHandlerLocator;
use GpsLab\Component\Query\Specification\SpecificationQueryHandler;
use GpsLab\Component\Query\Specification\ObviousSpecificationQuery;

// register query handler in handler locator
$locator = new DirectBindingQueryHandlerLocator();
$locator->registerHandler(ObviousSpecificationQuery::class, [new SpecificationQueryHandler($em), 'handleSpecification']);

// create bus with query handler locator
$bus = new HandlerLocatedQueryBus($locator);


// specification for get contact with id = 123
$spec = Spec::eq('id', 123);

Expand All @@ -33,6 +46,7 @@ $modifier = Spec::cache(3600);
// make specification query
$query = new ObviousSpecificationQuery('AcmeDemo:Contact', $spec, $modifier);


// get contact
$contact = $query_bus->handle($query);
```
Expand Down Expand Up @@ -86,9 +100,23 @@ class ContactWithIdentityQuery implements SpecificationQuery
And use it

```php
use GpsLab\Component\Query\Bus\HandlerLocatedQueryBus;
use GpsLab\Component\Query\Handler\Locator\DirectBindingQueryHandlerLocator;
use GpsLab\Component\Query\Specification\SpecificationQueryHandler;
use GpsLab\Component\Query\Specification\ObviousSpecificationQuery;

// register query handler in handler locator
$locator = new DirectBindingQueryHandlerLocator();
$locator->registerHandler(ContactWithIdentityQuery::class, [new SpecificationQueryHandler($em), 'handleSpecification']);

// create bus with query handler locator
$bus = new HandlerLocatedQueryBus($locator);


// make specification query
$query = new ContactWithIdentityQuery(123);


// get contact
$contact = $query_bus->handle($query);
```
Expand Down

0 comments on commit aa3be63

Please sign in to comment.