Download the PHP package ajgl/simple-bus-query-bus without Composer

On this page you can find all versions of the php package ajgl/simple-bus-query-bus. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package simple-bus-query-bus

AjglSimpleBusQueryBus

This package is an extension to the MessageBus package by @matthiasnoback intended to build query buses.

Build Status Latest Stable Version Latest Unstable Version Total Downloads Montly Downloads Daily Downloads License

It allows you to create a message bus that will catch the return value of the handling of the given message.

Installation

To install the latest stable version of this component, open a console and execute the following command:

Usage

Implementing a query bus

The classes and interfaces from this package can be used to set up a query bus. The characteristics of a query bus are:

Setting up the query bus

At least we need an instance of CatchReturnMessageBusSupportingMiddleware:

Defining the query handler map

Now we also want queries to be handled by exactly one query handler (which can be any callable). We first need to define the collection of handlers that are available in the application. We should make this query handler map lazy-loading, or every query handler will be fully loaded, even though it is not going to be used:

Each of the provided "callables" can be one of the following things:

For backwards compatibility an object with a handle() method also counts as a "callable".

Resolving the query handler for a query

The name of a query

First we need a way to resolve the name of a query. You can use the fully-qualified class name (FQCN) of a query object as its name:

Or you can ask query objects what their name is:

In that case your queries have to implement NamedMessage:

Implementing your own MessageNameResolver

If you want to use another rule to determine the name of a query, create a class that implements SimpleBus\Message\Name\MessageNameResolver.

Resolving the query handler based on the name of the query

Using the MessageNameResolver of your choice, you can now let the query handler resolver find the right query handler for a given query.

Finally, we should add some middleware to the query bus that calls the resolved query handler and catchs the handler result:

Using the query bus: an example

Consider the following query:

This query communicates the intention to "find an user by email address". The message data consists of an email address. This information is required to execute the desired behavior.

The handler for this query looks like this:

We should register this handler as a service and add the service id to the query handler map. Since we have already fully configured the query bus, we can just start creating a new query object and let the query bus handle it. Eventually the query will be passed as a message to the FindUserByEmailAddressQueryHandler:

Once handled the query, the $queryResult variable will contain the query result (the user found).

License

This component is under the MIT license. See the complete license in the LICENSE file.

Reporting an issue or a feature request

Issues and feature requests are tracked in the Github issue tracker.

Author Information

Developed with ♥ by Antonio J. García Lagar.

If you find this component useful, please add a ★ in the GitHub repository page and/or the Packagist package page.


All versions of simple-bus-query-bus with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
simple-bus/message-bus Version ^6
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ajgl/simple-bus-query-bus contains the following files

Loading the files please wait ....