Skip to content

Commit

Permalink
Update README and add Zend\ServiceManager configuration example
Browse files Browse the repository at this point in the history
  • Loading branch information
pauci committed Apr 25, 2017
1 parent 8dd7da5 commit 50be4ba
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
61 changes: 60 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,63 @@
[![Build Status](https://travis-ci.org/pauci/cqrs-factory.svg?branch=master)](https://travis-ci.org/pauci/cqrs)
[![Coverage Status](https://coveralls.io/repos/pauci/cqrs-factory/badge.png?branch=master)](https://coveralls.io/r/pauci/cqrs)

CQRS factories for container-interop
[CQRS](https://github.com/pauci/cqrs) factories for PSR-11

This package provides a set of factories to be used with containers using the PSR-11 standard for an easy
CQRS integration in a project.

## Installation

The easiest way to install this package is through composer:

```bash
$ composer require pauci/cqrs-factory
```

## Configuration

In the general case where you are only using a single command bus, it's enough to define the command bus factory:

```php
return [
'dependencies' => [
'factories' => [
'cqrs.command_bus.cqrs_default' => \CQRSFactory\CommandBusFactory::class,
],
],
];
```

If you want to add a second command bus, or use another name than "cqrs_default", you can do so by using the static
variants of the factories:

```php
return [
'dependencies' => [
'factories' => [
'cqrs.command_bus.cqrs_other' => [\CQRSFactory\CommandBusFactory::class, 'cqrs_other'],
],
],
];
```

Each factory supplied by this package will by default look for a registered factory in the container. If it cannot find
one, it will automatically pull its dependencies from on-the-fly created factories. This saves you the hassle of
registering factories in your container which you may not need at all. Of course, you can always register those
factories when required. The following additional factories are available:

- ```\CQRSFactory\EventBusFactory``` (cqrs.event_bus.*)
- ```\CQRSFactory\EventPublisherFactory``` (cqrs.event_publisher.*)
- ```\CQRSFactory\EventStoreFactory``` (cqrs.event_store.*)
- ```\CQRSFactory\IdentityMapFactory``` (cqrs.identity_map.*)
- ```\CQRSFactory\SerializerFactory``` (cqrs.serializer.*)
- ```\CQRSFactory\TransactionManagerFactory``` (cqrs.transaction_manager.*)

Each of those factories supports the same static behavior as the command bus factory. For container specific
configurations, there are a few examples provided in the example directory:

- [Zend\ServiceManager](example/zend-servicemanager.php)

## Example configuration

A complete example configuration can be found in [example/config.php](example/config.php).
16 changes: 16 additions & 0 deletions example/zend-servicemanager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
use Zend\ServiceManager\ServiceManager;

// Standard config keys
$container = new ServiceManager([
'factories' => [
'cqrs.command_bus.cqrs_default' => \CQRSFactory\CommandBusFactory::class,
],
]);

// Custom config keys
$container = new ServiceManager([
'factories' => [
'cqrs.command_bus.cqrs_other' => [\CQRSFactory\CommandBusFactory::class, 'cqrs_other'],
],
]);

0 comments on commit 50be4ba

Please sign in to comment.