Name |
Date |
Size |
#Lines |
LOC |
||
---|---|---|---|---|---|---|
.. | 28-Mar-2019 | - | ||||
Test/Unit/ | H | 28-Mar-2019 | - | 1,003 | 629 | |
.State | H A D | 27-Mar-2019 | 10 | 2 | 1 | |
Bucket.php | H A D | 27-Mar-2019 | 3.3 KiB | 137 | 36 | |
CHANGELOG.md | H A D | 27-Mar-2019 | 2.3 KiB | 45 | 34 | |
Event.php | H A D | 27-Mar-2019 | 7.4 KiB | 267 | 105 | |
Exception.php | H A D | 27-Mar-2019 | 1.9 KiB | 52 | 6 | |
Listenable.php | H A D | 27-Mar-2019 | 2.1 KiB | 58 | 6 | |
Listener.php | H A D | 27-Mar-2019 | 5.1 KiB | 185 | 63 | |
Listens.php | H A D | 27-Mar-2019 | 3 KiB | 107 | 30 | |
README.md | H A D | 27-Mar-2019 | 5.4 KiB | 162 | 120 | |
Source.php | H A D | 27-Mar-2019 | 1.8 KiB | 50 | 5 | |
composer.json | H A D | 27-Mar-2019 | 1.1 KiB | 43 | 42 |
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 [](https://webchat.freenode.net/?channels=#hoaproject) 22 [](https://gitter.im/hoaproject/central) 23 [](https://central.hoa-project.net/Documentation/Library/Event) 24 [](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