• Home
  • History
  • Annotate
Name
Date
Size
#Lines
LOC

..28-Mar-2019-

Test/Unit/H28-Mar-2019-1,003629

.StateH A D27-Mar-201910 21

Bucket.phpH A D27-Mar-20193.3 KiB13736

CHANGELOG.mdH A D27-Mar-20192.3 KiB4534

Event.phpH A D27-Mar-20197.4 KiB267105

Exception.phpH A D27-Mar-20191.9 KiB526

Listenable.phpH A D27-Mar-20192.1 KiB586

Listener.phpH A D27-Mar-20195.1 KiB18563

Listens.phpH A D27-Mar-20193 KiB10730

README.mdH A D27-Mar-20195.4 KiB162120

Source.phpH A D27-Mar-20191.8 KiB505

composer.jsonH A D27-Mar-20191.1 KiB4342

README.md

1 <p align="center">
2   <img src="https://static.hoa-project.net/Image/Hoa.svg" alt="Hoa" width="250px" />
3 </p>
4 
5 ---
6 
7 <p align="center">
8   <a href="https://travis-ci.org/hoaproject/event"><img src="https://img.shields.io/travis/hoaproject/event/master.svg" alt="Build status" /></a>
9   <a href="https://coveralls.io/github/hoaproject/event?branch=master"><img src="https://img.shields.io/coveralls/hoaproject/event/master.svg" alt="Code coverage" /></a>
10   <a href="https://packagist.org/packages/hoa/event"><img src="https://img.shields.io/packagist/dt/hoa/event.svg" alt="Packagist" /></a>
11   <a href="https://hoa-project.net/LICENSE"><img src="https://img.shields.io/packagist/l/hoa/event.svg" alt="License" /></a>
12 </p>
13 <p align="center">
14   Hoa is a <strong>modular</strong>, <strong>extensible</strong> and
15   <strong>structured</strong> set of PHP libraries.<br />
16   Moreover, Hoa aims at being a bridge between industrial and research worlds.
17 </p>
18 
19 # Hoa\Event
20 
21 [![Help on IRC](https://img.shields.io/badge/help-%23hoaproject-ff0066.svg)](https://webchat.freenode.net/?channels=#hoaproject)
22 [![Help on Gitter](https://img.shields.io/badge/help-gitter-ff0066.svg)](https://gitter.im/hoaproject/central)
23 [![Documentation](https://img.shields.io/badge/documentation-hack_book-ff0066.svg)](https://central.hoa-project.net/Documentation/Library/Event)
24 [![Board](https://img.shields.io/badge/organisation-board-ff0066.svg)](https://waffle.io/hoaproject/event)
25 
26 This library allows to use events and listeners in PHP. This is an observer
27 design-pattern implementation.
28 
29 [Learn more](https://central.hoa-project.net/Documentation/Library/Event).
30 
31 ## Installation
32 
33 With [Composer](https://getcomposer.org/), to include this library into
34 your dependencies, you need to
35 require [`hoa/event`](https://packagist.org/packages/hoa/event):
36 
37 ```sh
38 $ composer require hoa/event '~1.0'
39 ```
40 
41 For more installation procedures, please read [the Source
42 page](https://hoa-project.net/Source.html).
43 
44 ## Testing
45 
46 Before running the test suites, the development dependencies must be installed:
47 
48 ```sh
49 $ composer install
50 ```
51 
52 Then, to run all the test suites:
53 
54 ```sh
55 $ vendor/bin/hoa test:run
56 ```
57 
58 For more information, please read the [contributor
59 guide](https://hoa-project.net/Literature/Contributor/Guide.html).
60 
61 ## Quick usage
62 
63 We propose a quick overview of how to use events and listeners.
64 
65 ### Events
66 
67 An event is:
68   * **Asynchronous** when registering, because the observable may not exist yet
69     while observers start to observe,
70   * **Anonymous** when using, because the observable has no idea how many and
71     what observers are observing,
72   * It aims at a **large** diffusion of data through isolated components.
73     Wherever is the observable, we can observe its data.
74 
75 In Hoa, an event channel has the following form:
76 `hoa://Event/LibraryName/AnId:pseudo-class#anAnchor`. For instance, the
77 `hoa://Event/Exception` channel contains all exceptions that have been thrown.
78 The `hoa://Event/Stream/StreamName:close-before` contains all streams that are
79 about to close. Thus, the following example will observe all thrown exceptions:
80 
81 ```php
82 Hoa\Event\Event::getEvent('hoa://Event/Exception')->attach(
83     function (Hoa\Event\Bucket $bucket) {
84         var_dump(
85             $bucket->getSource(),
86             $bucket->getData()
87         );
88     }
89 );
90 ```
91 
92 Because `attach` expects a callable and because Hoa's callable implementation is
93 smart, we can directly attach a stream to an event, like:
94 
95 ```php
96 Hoa\Event\Event::getEvent('hoa://Event/Exception')->attach(
97     new Hoa\File\Write('Foo.log')
98 );
99 ```
100 
101 This way, all exceptions will be printed on the `Foo.log` file.
102 
103 ### Listeners
104 
105 Contrary to an event, a listener is:
106   * **Synchronous** when registering, because the observable must exist before
107     observers can observe,
108   * **Identified** when using, because the observable knows how many observers
109     are observing,
110   * It aims at a **close** diffusion of data. The observers must have an access
111     to the observable to observe.
112 
113 The `Hoa\Event\Listenable` interface requires the `on` method to be present to
114 register a listener to a listener ID. For instance, the following example
115 listens the `message` listener ID, i.e. when a message is received by the
116 WebSocket server, the closure is executed:
117 
118 ```php
119 $server = new Hoa\Websocket\Server(…);
120 $server->on('message', function (Hoa\Event\Bucket $bucket) {
121     var_dump(
122         $bucket->getSource(),
123         $bucket->getData()
124     );
125 });
126 ```
127 
128 ## Documentation
129 
130 The
131 [hack book of `Hoa\Event`](https://central.hoa-project.net/Documentation/Library/Event) contains
132 detailed information about how to use this library and how it works.
133 
134 To generate the documentation locally, execute the following commands:
135 
136 ```sh
137 $ composer require --dev hoa/devtools
138 $ vendor/bin/hoa devtools:documentation --open
139 ```
140 
141 More documentation can be found on the project's website:
142 [hoa-project.net](https://hoa-project.net/).
143 
144 ## Getting help
145 
146 There are mainly two ways to get help:
147 
148   * On the [`#hoaproject`](https://webchat.freenode.net/?channels=#hoaproject)
149     IRC channel,
150   * On the forum at [users.hoa-project.net](https://users.hoa-project.net).
151 
152 ## Contribution
153 
154 Do you want to contribute? Thanks! A detailed [contributor
155 guide](https://hoa-project.net/Literature/Contributor/Guide.html) explains
156 everything you need to know.
157 
158 ## License
159 
160 Hoa is under the New BSD License (BSD-3-Clause). Please, see
161 [`LICENSE`](https://hoa-project.net/LICENSE) for details.
162