scratch – Blame information for rev 122
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
120 | office | 1 | # Événement |
2 | |||
3 | Événement is a very simple event dispatching library for PHP. |
||
4 | |||
5 | It has the same design goals as [Silex](http://silex-project.org) and |
||
6 | [Pimple](http://pimple-project.org), to empower the user while staying concise |
||
7 | and simple. |
||
8 | |||
9 | It is very strongly inspired by the EventEmitter API found in |
||
10 | [node.js](http://nodejs.org). |
||
11 | |||
12 | [![Build Status](https://secure.travis-ci.org/igorw/evenement.png?branch=master)](http://travis-ci.org/igorw/evenement) |
||
13 | |||
14 | ## Fetch |
||
15 | |||
16 | The recommended way to install Événement is [through composer](http://getcomposer.org). |
||
17 | |||
18 | Just create a composer.json file for your project: |
||
19 | |||
20 | ```JSON |
||
21 | { |
||
22 | "require": { |
||
23 | "evenement/evenement": "2.0.*" |
||
24 | } |
||
25 | } |
||
26 | ``` |
||
27 | |||
28 | **Note:** The `2.0.*` version of Événement requires PHP 5.4. If you are |
||
29 | using PHP 5.3, please use the `1.0.*` version: |
||
30 | |||
31 | ```JSON |
||
32 | { |
||
33 | "require": { |
||
34 | "evenement/evenement": "1.0.*" |
||
35 | } |
||
36 | } |
||
37 | ``` |
||
38 | |||
39 | And run these two commands to install it: |
||
40 | |||
41 | $ curl -s http://getcomposer.org/installer | php |
||
42 | $ php composer.phar install |
||
43 | |||
44 | Now you can add the autoloader, and you will have access to the library: |
||
45 | |||
46 | ```php |
||
47 | <?php |
||
48 | require 'vendor/autoload.php'; |
||
49 | ``` |
||
50 | |||
51 | ## Usage |
||
52 | |||
53 | ### Creating an Emitter |
||
54 | |||
55 | ```php |
||
56 | <?php |
||
57 | $emitter = new Evenement\EventEmitter(); |
||
58 | ``` |
||
59 | |||
60 | ### Adding Listeners |
||
61 | |||
62 | ```php |
||
63 | <?php |
||
64 | $emitter->on('user.created', function (User $user) use ($logger) { |
||
65 | $logger->log(sprintf("User '%s' was created.", $user->getLogin())); |
||
66 | }); |
||
67 | ``` |
||
68 | |||
69 | ### Emitting Events |
||
70 | |||
71 | ```php |
||
72 | <?php |
||
73 | $emitter->emit('user.created', array($user)); |
||
74 | ``` |
||
75 | |||
76 | Tests |
||
77 | ----- |
||
78 | |||
79 | $ phpunit |
||
80 | |||
81 | License |
||
82 | ------- |
||
83 | MIT, see LICENSE. |