2017 © Pedro Peláez
 

library querybus

A simple bus for queries

image

smoothphp/querybus

A simple bus for queries

  • Thursday, November 16, 2017
  • by mrsimonbennett
  • Repository
  • 2 Watchers
  • 6 Stars
  • 29,459 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 7 Versions
  • 4 % Grown

The README.md

Query Bus

Latest Version on Packagist ![Software License][ico-license] Build Status ![Coverage Status][ico-scrutinizer] Quality Score ![Total Downloads][ico-downloads], (*1)

Install

Via Composer, (*2)

``` bash $ composer require smoothphp/querybus, (*3)


## Usage The query bus exists to execute queries within the domain of the application. Typically these are read only commands, with write operations being performed using the [Command Bus](https://github.com/SmoothPhp/CommandBus). The QueryBus is a simple concept, and leaves the majority of the implementation decisions to the developer. A simple implementation is provided for Laravel users. The query bus exists of 3 components. * Query The DTO containing the intent and parameters for the query. * Query Bus Takes a query object, resolves the query handler, and executes it. * Query Translator Takes a query, and translates to the query handler class name. ### Laravel Users The Laravel Query bus takes a Query object, and resolves the handler by adding 'Handler' to the class name. This handler class is then resolved by the container and all dependencies are injected. For example, `App\Queries\FindUserById` is resolved to `App\Queries\FindUserByIdHandler`, and the `handle` method is executed. You are free to implement query handler resolution however you like, though. #### Service Provider ```php <?php return [ // ... 'providers' => [ // ... SmoothPhp\QueryBus\Laravel\LaravelQueryBusServiceProvider::class, ], ];

Query

<?php

class FindUserById {
    public $id;
    public function __construct(string $id) {
        $this->id = $id;
    }
}

Query Handler

<?php

class FindUserByIdHandler {
    private $client;

    public function __construct(DBClient $client) {
        $this->client = $client;
    }

    public function handle(FindUserById $query) {
        return $this->client->table('users')->where('id', $query->id)->get();
    }
}

Using

<?php

class ExampleController extends Controller {
    private $bus;

    public function __construct(\SmoothPhp\QueryBus\QueryBus $queryBus) {
        $this->bus = $queryBus;
    }

    public function showUser(string $userId) {
        return view('users.show')->with('user', $this->bus->query(new FindUserById($userId)));
    }
}

Change log

Please see CHANGELOG for more information what has changed recently., (*4)

Testing

bash $ composer test, (*5)

Contributing

Please see CONTRIBUTING and CONDUCT for details., (*6)

Security

If you discover any security related issues, please email simon@smoothphp.com instead of using the issue tracker., (*7)

Credits

License

The MIT License (MIT). Please see License File for more information., (*8)

The Versions

16/11 2017

dev-master

9999999-dev https://github.com/smoothphp/querybus

A simple bus for queries

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

cqrs event sourcing smoothphp querybus

16/11 2017

v1.0.2

1.0.2.0 https://github.com/smoothphp/querybus

A simple bus for queries

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

cqrs event sourcing smoothphp querybus

16/11 2017

dev-feature/auto-discovery

dev-feature/auto-discovery https://github.com/smoothphp/querybus

A simple bus for queries

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

cqrs event sourcing smoothphp querybus

17/03 2017

v1.0.1

1.0.1.0 https://github.com/smoothphp/querybus

A simple bus for queries

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

cqrs event sourcing smoothphp querybus

08/03 2017

v1.0.0

1.0.0.0 https://github.com/smoothphp/querybus

A simple bus for queries

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

cqrs event sourcing smoothphp querybus

08/03 2017

v0.0.2

0.0.2.0 https://github.com/smoothphp/querybus

A simple bus for queries

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

cqrs event sourcing smoothphp querybus

15/12 2015

0.0.1

0.0.1.0 https://github.com/smoothphp/querybus

A simple bus for queries

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

cqrs event sourcing smoothphp querybus