Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a Readme and a composer.json for the Event library
- Loading branch information
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# CakePHP Event Library | ||
|
||
This library emulates several aspects of how events are triggered and managed in popular JavaScript | ||
libraries such as jQuery: An event object is dispatched to all listeners. The event object holds information | ||
about the event, and provides the ability to stop event propagation at any point. | ||
Listeners can register themselves or can delegate this task to other objects and have the chance to alter the | ||
state and the event itself for the rest of the callbacks. | ||
|
||
## Usage | ||
|
||
Collections can be created using an array or Traversable object. A simple use of a Collection would be: | ||
|
||
```php | ||
use Cake\Event\Event; | ||
use Cake\Event\EventManagerTrait; | ||
|
||
class Orders { | ||
|
||
use EventManagerTrait; | ||
|
||
public function placeOrder($order) { | ||
$this->doStuff(); | ||
$event = new Event('Orders.afterPlace', $this, [ | ||
'order' => $order | ||
]); | ||
$this->eventManager()->dispatch($event); | ||
} | ||
} | ||
|
||
$orders = new Orders(); | ||
$orders->eventManager()->attach(function($event) { | ||
// Do something after the order was placed | ||
... | ||
}, 'Orders.afterPlace'); | ||
|
||
$orders->placeOrder($order); | ||
``` | ||
|
||
The above code allows you to easily notify the other parts of the application that an order has been created. | ||
You can then do tasks like send email notifications, update stock, log relevant statistics and other tasks | ||
in separate objects that focus on those concerns. | ||
|
||
## Documentation | ||
|
||
Please make sure you check the [official documentation](http://book.cakephp.org/3.0/en/core-libraries/events.html) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "cakephp/event", | ||
"description": "CakePHP event dispatcher library that helps implementing the observer pattern", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "CakePHP Community", | ||
"homepage": "http://cakephp.org" | ||
} | ||
], | ||
"minimum-stability": "beta" | ||
} |