2017 © Pedro Peláez
 

library query-bus

A PHP library for Interrogatory Messages.

image

gnugat/query-bus

A PHP library for Interrogatory Messages.

  • Thursday, July 2, 2015
  • by gnupat
  • Repository
  • 2 Watchers
  • 1 Stars
  • 63 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

QueryBus SensioLabsInsight Travis CI

A PHP library for Interrogatory Messages., (*1)

Interrogatory Messages are passed to the QueryBus service which returns the result of the first QueryMatcher that supports it., (*2)

Installation

QueryBus can be installed using Composer:, (*3)

composer require "gnugat/query-bus:~2.0"

Simple conversion

Let's take the following table:, (*4)

CREATE TABLE article (
    id int,
    title VARCHAR(255),
    content TEXT
);

If we want to execute the following query:, (*5)

SELECT id, title, content FROM article WHERE id = 42;

Then we have first to create a Query, which is a simple DTO:, (*6)

<?php

require __DIR__.'/vendor/autoload.php';

use Gnugat\QueryBus\QueryBus;

class GetArticle
{
    public $id;

    public function __construct($id)
    {
        if (null === $id) {
            throw new \InvalidArgumentException('Required parameter ID is missing');
        }
        $this->id = (int) $id;
    }
}

Note: Queries can contain simple validation, for example to check for null values., (*7)

Then we have to create a QueryMatcher:, (*8)

// ...

use Gnugat\QueryBus\QueryMatcher;

class GetArticleMatcher implements QueryMatcher
{
    private $connection;

    public function __construct($connection)
    {
        $this->connection = $connection;
        pg_prepare($this->connection, 'get_article', 'SELECT id, title, content FROM articles WHERE id = $1');
    }

    public function supports($query)
    {
        return $query instanceof GetArticle;
    }

    public function match($query)
    {
        $result = pg_execute($this->connection, 'get_article', array($query->id));

        return pg_fetch_array($result, NULL, PGSQL_ASSOC);
    }
}

Next we need to register it in QueryBus:, (*9)

// ...

use Gnugat\QueryBus\QueryBus;

$connection = pg_pconnect('dbname=blog');
$queryBus = new QueryBus();
$queryBus->add(new GetArticleMatcher($connection));

Finally we can actually execute the query:, (*10)

// ...

$articles = $queryBus->match(new GetArticle(42));

Further documentation

You can see the current and past versions using one of the following:, (*11)

You can find more documentation at the following links:, (*12)

The Versions

02/07 2015

dev-master

9999999-dev https://gnugat.github.io/query-bus

A PHP library for Interrogatory Messages.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

bundle symfony query bus message interrogatory

31/05 2015

v2.0.1

2.0.1.0 https://gnugat.github.io/query-bus

A PHP library for Interrogatory Messages.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

bundle symfony query bus message interrogatory

31/05 2015

v2.0.0

2.0.0.0

Smart Product

  Sources   Download

proprietary

The Requires

  • php >=5.3.3

 

The Development Requires

26/05 2015

v1.0.0

1.0.0.0

A PHP library for Interrogatory Messages

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

query bus message interrogatory