Skip to content
This repository has been archived by the owner on Dec 22, 2017. It is now read-only.

Commit

Permalink
Deprecate this package
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasnoback committed Jan 14, 2015
1 parent 44578d8 commit 24c6641
Show file tree
Hide file tree
Showing 16 changed files with 4 additions and 1,268 deletions.
4 changes: 0 additions & 4 deletions .gitattributes
@@ -1,7 +1,3 @@
/tests export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/phpunit.xml export-ignore
/phpunit.xml.dist export-ignore
/composer.lock export-ignore
1 change: 0 additions & 1 deletion .gitignore
@@ -1,2 +1 @@
vendor/
phpunit.xml
11 changes: 0 additions & 11 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
@@ -1,4 +1,4 @@
Copyright (c) 2014 Matthias Noback
Copyright (c) 2014-2015 Matthias Noback

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
122 changes: 1 addition & 121 deletions README.md
@@ -1,121 +1 @@
# EventBus

[![Build Status](https://travis-ci.org/SimleBus/EventBus.svg?branch=master)](https://travis-ci.org/SimpleBus/EventBus)

By [Matthias Noback](http://php-and-symfony.matthiasnoback.nl/)

## Installation

Using Composer:

composer require simple-bus/event-bus

## Usage

1. Create an event

```php
use SimpleBus\Event\Event;

class UserRegisteredEvent implements Event
{
}
```

2. Create an event subscriber

```php
use SimpleBus\Message\Subscriber\MessageSubscriber;
use SimpleBus\Message\Message;

class SendConfirmationMailWhenUserRegistered implements MessageSubscriber
{
public function notify(Message $event)
{
...
}
}
```

3. Set up the event bus and the event subscribers resolver:

```php
use SimpleBus\Message\Subscriber\Resolver\MessageSubscribersResolver;
use SimpleBus\Message\Subscriber\Resolver\NameBasedMessageSubscriberResolver;
use SimpleBus\Message\Name\ClassBasedNameResolver;
use SimpleBus\Message\Subscriber\NotifiesMessageSubscribersMiddleware;
use SimpleBus\Message\Subscriber\Collection\LazyLoadingMessageSubscriberCollection;

$messageNameResolver = new ClassBasedNameResolver();
$subscriberCollection = new LazyLoadingMessageSubscriberCollection(
[
UserRegisteredEvent::class => array(
'send_confirmation_mail_when_user_registered_service_id',
// add other subscriber service ids
...
)
],
function ($serviceId) {
// lazily load/create instances of the given event handler service, e.g. using a service locator
$handler = ...;

return $handler;
}
);

$eventSubscribersResolver = new NameBasedMessageSubscriberResolver(
$messageNameResolver,
$subscriberCollection
);

$eventBusMiddleware = new NotifiesMessageSubscribersMiddleware($eventSubscribersResolver);
$eventBus->addMiddleware($eventBusMiddleware);

$userRegisteredEvent = new UserRegisteredEvent();

$eventBus->handle($userRegisteredEvent);
```

Because an event handler might call the event bus to handle new events, it's better to add a specialized middleware to
make sure that the first event is fully handled first:

```php
use SimpleBus\Message\Bus\Middleware\FinishesHandlingMessageBeforeHandlingNext;

// N.B. add this middleware before adding other middlewares
$eventBus->addMiddleware(new FinishesHandlingMessageBeforeHandlingNext());
```

### Event providers

Because it is very likely that in your application events originate from other objects that collect and later provide
events, this library contains a set of basic classes and interfaces for those types of event providers too.

```php
use SimpleBus\Event\Provider\ProvidesEvents;
use SimpleBus\Event\Provider\EventProviderCapabilities;

class User implements ProvidesEvents
{
use EventProviderCapabilities;

public static function register($email)
{
return new self($email);
}

private function __construct($email)
{
$this->raise(new UserRegisteredEvent());
}
}
```

Afterwards you can collect events from the entity:

```php
$user = User::register('matthiasnoback@gmail.com');

// $events will be an array containing an object of type UserRegisteredEvent
$events = $user->releaseEvents();
```
**This package has been deprecated, use [SimpleBus/MessageBus](https://github.com/SimpleBus/MessageBus) instead.**
23 changes: 2 additions & 21 deletions composer.json
@@ -1,8 +1,7 @@
{
"name": "simple-bus/event-bus",
"type": "library",
"description": "Stand-alone event bus library for PHP",
"keywords": ["event", "event bus"],
"description": "Deprecated package",
"homepage": "http://github.com/SimpleBus/EventBus",
"license": "MIT",
"authors": [
Expand All @@ -12,26 +11,8 @@
"homepage": "http://php-and-symfony.matthiasnoback.nl"
}
],
"require": {
"php": ">=5.4",
"simple-bus/message-bus": "~1.0@dev",
"beberlei/assert": "~2.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"suggest": {
"simple-bus/command-bus": "Simple command bus implementation",
"simple-bus/doctrine-orm-bridge": "Bridge for using command buses and event buses with Doctrine ORM",
"simple-bus/symfony-bridge": "Bridge for using command buses and event buses with Symfony"
},
"minimum-stability": "dev",
"prefer-stable": true,
"autoload": {
"psr-4" : { "SimpleBus\\Event\\" : "src" }
},
"autoload-dev": {
"psr-4" : { "SimpleBus\\Event\\Tests\\" : "tests" }
"simple-bus/message-bus": "Use this package instead"
},
"extra": {
"branch-alias": {
Expand Down

0 comments on commit 24c6641

Please sign in to comment.