PHPackages                             smoothphp/querybus - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. smoothphp/querybus

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

smoothphp/querybus
==================

A simple bus for queries

v1.0.2(8y ago)1085.2k↓69.2%3MITPHPPHP &gt;=7.0.0

Since Dec 15Pushed 8y ago1 watchersCompare

[ Source](https://github.com/SmoothPhp/QueryBus)[ Packagist](https://packagist.org/packages/smoothphp/querybus)[ Docs](https://github.com/smoothphp/querybus)[ RSS](/packages/smoothphp-querybus/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (4)Versions (7)Used By (0)

Query Bus
=========

[](#query-bus)

[![Latest Version on Packagist](https://camo.githubusercontent.com/cb14382324110964955622a021cb77d44d283e10840945f1f7ba7bcbf56fbdab/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736d6f6f74687068702f71756572796275732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/smoothphp/querybus)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/3ebd333ce4451c39eb6eb9fe43dc7df0b68339299abeab9d71a22192df53fc65/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f736d6f6f74687068702f71756572796275732f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/smoothphp/querybus)[![Coverage Status](https://camo.githubusercontent.com/63227f174b03c851dd80f8b303b7c924c58e55ab014cb7b4a74b75f2b9bf9d25/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f736d6f6f74687068702f71756572796275732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/smoothphp/querybus/code-structure)[![Quality Score](https://camo.githubusercontent.com/92f7503d090a05517571a21fc14494bbc223cf314bc9d028aff852bd6d64bd5f/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f736d6f6f74687068702f71756572796275732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/smoothphp/querybus)[![Total Downloads](https://camo.githubusercontent.com/4a3202ce7e1b4c27e9e1dbff201c161251d9b80d7b30feeea68864249b93237c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f736d6f6f74687068702f71756572796275732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/smoothphp/querybus)

Install
-------

[](#install)

Via Composer

```
$ composer require smoothphp/querybus
```

Usage
-----

[](#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

[](#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

[](#service-provider)

```
