2017 © Pedro Peláez
 

library specification-query

The simple infrastructure component for use a Doctrine specification as query in CQRS architecture

image

gpslab/specification-query

The simple infrastructure component for use a Doctrine specification as query in CQRS architecture

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Latest Stable Version Total Downloads Build Status Coverage Status Scrutinizer Code Quality SensioLabs Insight StyleCI License, (*1)

Doctrine Specification as query in CQRS architecture

The simple infrastructure component for use a Doctrine Specification as query in CQRS architecture., (*2)

Installation

Pretty simple with Composer, run:, (*3)

composer require gpslab/specification-query

Usage

You can use Specifications as a simple query., (*4)

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);

// cache the result by 1 hour
$modifier = Spec::cache(3600);

// make specification query
$query = new ObviousSpecificationQuery('AcmeDemo:Contact', $spec, $modifier);


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

Custom query

You can create custom query for this case., (*5)

class ContactWithIdentityQuery implements SpecificationQuery
{
    /**
     * @var int
     */
    private $id;

    /**
     * @param int $id
     */
    public function __construct($id)
    {
        $this->id = $id;
    }

    /**
     * @return string
     */
    public function entity()
    {
        return 'AcmeDemo:Contact';
    }

    /**
     * @return Specification
     */
    public function spec()
    {
        return Spec::eq('id', $this->id);
    }

    /**
     * @return ResultModifier|null
     */
    public function modifier()
    {
        return Spec::cache(3600);
    }
}

And use it, (*6)

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);

License

This bundle is under the MIT license. See the complete license in the file: LICENSE, (*7)

The Versions

13/07 2017

dev-master

9999999-dev https://github.com/gpslab/specification-query

The simple infrastructure component for use a Doctrine specification as query in CQRS architecture

  Sources   Download

MIT

The Requires

 

The Development Requires

doctrine query specification cqrs infrastructure doctrine-orm

23/06 2017

v1.0.0

1.0.0.0 https://github.com/gpslab/specification-query

The simple infrastructure component for use a Doctrine specification as query in CQRS architecture

  Sources   Download

MIT

The Requires

 

The Development Requires

doctrine query specification cqrs infrastructure doctrine-orm