aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2015-11-10 21:28:31 +0100
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2015-11-11 13:35:21 +0100
commitb4e93098824b68137b79c2908f790284902ed4c6 (patch)
treeb544c1d8bfcd0f1d22835286704eab46371233ca
downloadEvent-b4e93098824b68137b79c2908f790284902ed4c6.zip
Event-b4e93098824b68137b79c2908f790284902ed4c6.tar.gz
Event-b4e93098824b68137b79c2908f790284902ed4c6.tar.bz2
Split from `Hoa\Core`.
Our goal is to split `Hoa\Core` into several libraries. `Hoa\Event` is the result of this split.
-rw-r--r--.State1
-rw-r--r--Bucket.php137
-rw-r--r--Event.php253
-rw-r--r--Exception.php51
-rw-r--r--Listenable.php57
-rw-r--r--Listener.php185
-rw-r--r--README.md39
-rw-r--r--Source.php49
-rw-r--r--composer.json39
9 files changed, 811 insertions, 0 deletions
diff --git a/.State b/.State
new file mode 100644
index 0000000..65b2df8
--- /dev/null
+++ b/.State
@@ -0,0 +1 @@
+beta
diff --git a/Bucket.php b/Bucket.php
new file mode 100644
index 0000000..440bf79
--- /dev/null
+++ b/Bucket.php
@@ -0,0 +1,137 @@
+<?php
+
+/**
+ * Hoa
+ *
+ *
+ * @license
+ *
+ * New BSD License
+ *
+ * Copyright © 2007-2015, Hoa community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Hoa nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+namespace Hoa\Event;
+
+/**
+ * Class \Hoa\Event\Bucket.
+ *
+ * This class is the object which is transmit through event channels.
+ *
+ * @copyright Copyright © 2007-2015 Hoa community
+ * @license New BSD License
+ */
+class Bucket
+{
+ /**
+ * Source object.
+ *
+ * @var \Hoa\Event\Source
+ */
+ protected $_source = null;
+
+ /**
+ * Data.
+ *
+ * @var mixed
+ */
+ protected $_data = null;
+
+
+
+ /**
+ * Set data.
+ *
+ * @param mixed $data Data.
+ * @return void
+ */
+ public function __construct($data = null)
+ {
+ $this->setData($data);
+
+ return;
+ }
+
+ /**
+ * Send this object on the event channel.
+ *
+ * @param string $eventId Event ID.
+ * @param \Hoa\Event\Source $source Source.
+ * @return void
+ */
+ public function send($eventId, Source $source)
+ {
+ return Event::notify($eventId, $source, $this);
+ }
+
+ /**
+ * Set source.
+ *
+ * @param \Hoa\Event\Source $source Source.
+ * @return \Hoa\Event\Source
+ */
+ public function setSource(Source $source)
+ {
+ $old = $this->_source;
+ $this->_source = $source;
+
+ return $old;
+ }
+
+ /**
+ * Get source.
+ *
+ * @return \Hoa\Event\Source
+ */
+ public function getSource()
+ {
+ return $this->_source;
+ }
+
+ /**
+ * Set data.
+ *
+ * @param mixed $data Data.
+ * @return mixed
+ */
+ public function setData($data)
+ {
+ $old = $this->_data;
+ $this->_data = $data;
+
+ return $old;
+ }
+
+ /**
+ * Get data.
+ *
+ * @return mixed
+ */
+ public function getData()
+ {
+ return $this->_data;
+ }
+}
diff --git a/Event.php b/Event.php
new file mode 100644
index 0000000..ed67a8b
--- /dev/null
+++ b/Event.php
@@ -0,0 +1,253 @@
+<?php
+
+/**
+ * Hoa
+ *
+ *
+ * @license
+ *
+ * New BSD License
+ *
+ * Copyright © 2007-2015, Hoa community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Hoa nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+namespace Hoa\Event;
+
+use Hoa\Core;
+
+/**
+ * Class \Hoa\Event\Event.
+ *
+ * Events are asynchronous at registration, anonymous at use (until we
+ * receive a bucket) and useful to largely spread data through components
+ * without any known connection between them.
+ *
+ * @copyright Copyright © 2007-2015 Hoa community
+ * @license New BSD License
+ */
+class Event
+{
+ /**
+ * Static register of all observable objects, i.e. \Hoa\Event\Source
+ * object, i.e. object that can send event.
+ *
+ * @var array
+ */
+ private static $_register = [];
+
+ /**
+ * Callables, i.e. observer objects.
+ *
+ * @var array
+ */
+ protected $_callable = [];
+
+
+
+ /**
+ * Privatize the constructor.
+ *
+ * @return void
+ */
+ private function __construct()
+ {
+ return;
+ }
+
+ /**
+ * Manage multiton of events, with the principle of asynchronous
+ * attachements.
+ *
+ * @param string $eventId Event ID.
+ * @return \Hoa\Core\Event
+ */
+ public static function getEvent($eventId)
+ {
+ if (!isset(self::$_register[$eventId][0])) {
+ self::$_register[$eventId] = [
+ 0 => new self(),
+ 1 => null
+ ];
+ }
+
+ return self::$_register[$eventId][0];
+ }
+
+ /**
+ * Declare a new object in the observable collection.
+ * Note: Hoa's libraries use hoa://Event/AnID for their observable objects;
+ *
+ * @param string $eventId Event ID.
+ * @param \Hoa\Event\Source $source Observable object.
+ * @return void
+ * @throws \Hoa\Event\Exception
+ */
+ public static function register($eventId, $source)
+ {
+ if (true === self::eventExists($eventId)) {
+ throw new Exception(
+ 'Cannot redeclare an event with the same ID, i.e. the event ' .
+ 'ID %s already exists.',
+ 0,
+ $eventId
+ );
+ }
+
+ if (is_object($source) && !($source instanceof Source)) {
+ throw new Exception(
+ 'The source must implement \Hoa\Core\Event\Source ' .
+ 'interface; given %s.',
+ 1,
+ get_class($source)
+ );
+ } else {
+ $reflection = new \ReflectionClass($source);
+
+ if (false === $reflection->implementsInterface('\Hoa\Event\Source')) {
+ throw new Exception(
+ 'The source must implement \Hoa\Core\Event\Source ' .
+ 'interface; given %s.',
+ 2,
+ $source
+ );
+ }
+ }
+
+ if (!isset(self::$_register[$eventId][0])) {
+ self::$_register[$eventId][0] = new self();
+ }
+
+ self::$_register[$eventId][1] = $source;
+
+ return;
+ }
+
+ /**
+ * Undeclare an object in the observable collection.
+ *
+ * @param string $eventId Event ID.
+ * @param bool $hard If false, just delete the source, else,
+ * delete source and attached callables.
+ * @return void
+ */
+ public static function unregister($eventId, $hard = false)
+ {
+ if (false !== $hard) {
+ unset(self::$_register[$eventId]);
+ } else {
+ self::$_register[$eventId][1] = null;
+ }
+
+ return;
+ }
+
+ /**
+ * Attach an object to an event.
+ * It can be a callable or an accepted callable form (please, see the
+ * \Hoa\Core\Consistency\Xcallable class).
+ *
+ * @param mixed $callable Callable.
+ * @return \Hoa\Core\Event
+ */
+ public function attach($callable)
+ {
+ $callable = xcallable($callable);
+ $this->_callable[$callable->getHash()] = $callable;
+
+ return $this;
+ }
+
+ /**
+ * Detach an object to an event.
+ * Please see $this->attach() method.
+ *
+ * @param mixed $callable Callable.
+ * @return \Hoa\Event\Event
+ */
+ public function detach($callable)
+ {
+ unset($this->_callable[xcallable($callable)->getHash()]);
+
+ return $this;
+ }
+
+ /**
+ * Check if at least one callable is attached to an event.
+ *
+ * @return bool
+ */
+ public function isListened()
+ {
+ return !empty($this->_callable);
+ }
+
+ /**
+ * Notify, i.e. send data to observers.
+ *
+ * @param string $eventId Event ID.
+ * @param \Hoa\Event\Source $source Source.
+ * @param \Hoa\Event\Bucket $data Data.
+ * @return void
+ * @throws \Hoa\Event\Exception
+ */
+ public static function notify($eventId, Source $source, Bucket $data)
+ {
+ if (false === self::eventExists($eventId)) {
+ throw new Exception(
+ 'Event ID %s does not exist, cannot send notification.',
+ 3,
+ $eventId
+ );
+ }
+
+ $data->setSource($source);
+ $event = self::getEvent($eventId);
+
+ foreach ($event->_callable as $callable) {
+ $callable($data);
+ }
+
+ return;
+ }
+
+ /**
+ * Check whether an event exists.
+ *
+ * @param string $eventId Event ID.
+ * @return bool
+ */
+ public static function eventExists($eventId)
+ {
+ return
+ array_key_exists($eventId, self::$_register) &&
+ self::$_register[$eventId][1] !== null;
+ }
+}
+
+/**
+ * Flex entity.
+ */
+Core\Consistency::flexEntity('Hoa\Event\Event');
diff --git a/Exception.php b/Exception.php
new file mode 100644
index 0000000..1a20c0a
--- /dev/null
+++ b/Exception.php
@@ -0,0 +1,51 @@
+<?php
+
+/**
+ * Hoa
+ *
+ *
+ * @license
+ *
+ * New BSD License
+ *
+ * Copyright © 2007-2015, Hoa community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Hoa nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+namespace Hoa\Event;
+
+use Hoa\Core;
+
+/**
+ * Class \Hoa\Event\Exception.
+ *
+ * Extending the \Hoa\Core\Exception class.
+ *
+ * @copyright Copyright © 2007-2015 Hoa community
+ * @license New BSD License
+ */
+class Exception extends Core\Exception
+{
+}
diff --git a/Listenable.php b/Listenable.php
new file mode 100644
index 0000000..30d7958
--- /dev/null
+++ b/Listenable.php
@@ -0,0 +1,57 @@
+<?php
+
+/**
+ * Hoa
+ *
+ *
+ * @license
+ *
+ * New BSD License
+ *
+ * Copyright © 2007-2015, Hoa community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Hoa nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+namespace Hoa\Event;
+
+/**
+ * Interface \Hoa\Event\Listenable.
+ *
+ * Each object which is listenable must implement this interface.
+ *
+ * @copyright Copyright © 2007-2015 Hoa community
+ * @license New BSD License
+ */
+interface Listenable extends Source
+{
+ /**
+ * Attach a callable to a listenable component.
+ *
+ * @param string $listenerId Listener ID.
+ * @param mixed $callable Callable.
+ * @return \Hoa\Event\Listenable
+ */
+ public function on($listenerId, $callable);
+}
diff --git a/Listener.php b/Listener.php
new file mode 100644
index 0000000..19181da
--- /dev/null
+++ b/Listener.php
@@ -0,0 +1,185 @@
+<?php
+
+/**
+ * Hoa
+ *
+ *
+ * @license
+ *
+ * New BSD License
+ *
+ * Copyright © 2007-2015, Hoa community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Hoa nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+namespace Hoa\Event;
+
+/**
+ * Class \Hoa\Event\Listener.
+ *
+ * A contrario of events, listeners are synchronous, identified at use and
+ * useful for close interactions between one or some components.
+ *
+ * @copyright Copyright © 2007-2015 Hoa community
+ * @license New BSD License
+ */
+class Listener
+{
+ /**
+ * Source of listener (for Bucket).
+ *
+ * @var \Hoa\Event\Listenable
+ */
+ protected $_source = null;
+
+ /**
+ * All listener IDs and associated listeners.
+ *
+ * @var array
+ */
+ protected $_callables = [];
+
+
+
+ /**
+ * Build a listener.
+ *
+ * @param \Hoa\Event\Listenable $source Source (for Bucket).
+ * @param array $ids Accepted ID.
+ * @return void
+ */
+ public function __construct(Listenable $source, Array $ids)
+ {
+ $this->_source = $source;
+ $this->addIds($ids);
+
+ return;
+ }
+
+ /**
+ * Add acceptable ID (or reset).
+ *
+ * @param array $ids Accepted ID.
+ * @return void
+ */
+ public function addIds(Array $ids)
+ {
+ foreach ($ids as $id) {
+ $this->_callables[$id] = [];
+ }
+
+ return;
+ }
+
+ /**
+ * Attach a callable to a listenable component.
+ *
+ * @param string $listenerId Listener ID.
+ * @param mixed $callable Callable.
+ * @return \Hoa\Event\Listener
+ * @throws \Hoa\Event\Exception
+ */
+ public function attach($listenerId, $callable)
+ {
+ if (false === $this->listenerExists($listenerId)) {
+ throw new Exception(
+ 'Cannot listen %s because it is not defined.',
+ 0,
+ $listenerId
+ );
+ }
+
+ $callable = xcallable($callable);
+ $this->_callables[$listenerId][$callable->getHash()] = $callable;
+
+ return $this;
+ }
+
+ /**
+ * Detach a callable from a listenable component.
+ *
+ * @param string $listenerId Listener ID.
+ * @param mixed $callable Callable.
+ * @return \Hoa\Event\Listener
+ */
+ public function detach($listenerId, $callable)
+ {
+ unset($this->_callables[$listenerId][xcallable($callable)->getHash()]);
+
+ return $this;
+ }
+
+ /**
+ * Detach all callables from a listenable component.
+ *
+ * @param string $listenerId Listener ID.
+ * @return \Hoa\Event\Listener
+ */
+ public function detachAll($listenerId)
+ {
+ unset($this->_callables[$listenerId]);
+
+ return $this;
+ }
+
+ /**
+ * Check if a listener exists.
+ *
+ * @param string $listenerId Listener ID.
+ * @return bool
+ */
+ public function listenerExists($listenerId)
+ {
+ return array_key_exists($listenerId, $this->_callables);
+ }
+
+ /**
+ * Send/fire a bucket to a listener.
+ *
+ * @param string $listenerId Listener ID.
+ * @param \Hoa\Event\Bucket $data Data.
+ * @return array
+ * @throws \Hoa\Event\Exception
+ */
+ public function fire($listenerId, Bucket $data)
+ {
+ if (false === $this->listenerExists($listenerId)) {
+ throw new Exception(
+ 'Cannot fire on %s because it is not defined.',
+ 1,
+ $listenerId
+ );
+ }
+
+ $data->setSource($this->_source);
+ $out = [];
+
+ foreach ($this->_callables[$listenerId] as $callable) {
+ $out[] = $callable($data);
+ }
+
+ return $out;
+ }
+}
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..ec3f155
--- /dev/null
+++ b/README.md
@@ -0,0 +1,39 @@
+![Hoa](http://static.hoa-project.net/Image/Hoa_small.png)
+
+Hoa is a **modular**, **extensible** and **structured** set of PHP libraries.
+Moreover, Hoa aims at being a bridge between industrial and research worlds.
+
+# Hoa\Event ![state](http://central.hoa-project.net/State/Event)
+
+This library allows to use events and listeners in PHP.
+
+## Installation
+
+With [Composer](http://getcomposer.org/), to include this library into your
+dependencies, you need to require
+[`hoa/event`](https://packagist.org/packages/hoa/event):
+
+```json
+{
+ "require": {
+ "hoa/event": "~0.0"
+ }
+}
+```
+
+Please, read the website to [get more informations about how to
+install](http://hoa-project.net/Source.html).
+
+## Quick usage
+
+…
+
+## Documentation
+
+Different documentations can be found on the website:
+[http://hoa-project.net/](http://hoa-project.net/).
+
+## License
+
+Hoa is under the New BSD License (BSD-3-Clause). Please, see
+[`LICENSE`](http://hoa-project.net/LICENSE).
diff --git a/Source.php b/Source.php
new file mode 100644
index 0000000..89b14db
--- /dev/null
+++ b/Source.php
@@ -0,0 +1,49 @@
+<?php
+
+/**
+ * Hoa
+ *
+ *
+ * @license
+ *
+ * New BSD License
+ *
+ * Copyright © 2007-2015, Hoa community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Hoa nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+namespace Hoa\Event;
+
+/**
+ * Interface \Hoa\Event\Source.
+ *
+ * Each object which is observable must implement this interface.
+ *
+ * @copyright Copyright © 2007-2015 Hoa community
+ * @license New BSD License
+ */
+interface Source
+{
+}
diff --git a/composer.json b/composer.json
new file mode 100644
index 0000000..bc93572
--- /dev/null
+++ b/composer.json
@@ -0,0 +1,39 @@
+{
+ "name" : "hoa/event",
+ "description": "The Hoa\\Event library.",
+ "type" : "library",
+ "keywords" : ["library", "event", "listener"],
+ "homepage" : "http://hoa-project.net/",
+ "license" : "BSD-3-Clause",
+ "authors" : [
+ {
+ "name" : "Ivan Enderlin",
+ "email": "ivan.enderlin@hoa-project.net"
+ },
+ {
+ "name" : "Hoa community",
+ "homepage": "http://hoa-project.net/"
+ }
+ ],
+ "support": {
+ "email" : "support@lists.hoa-project.net",
+ "irc" : "irc://irc.freenode.org/hoaproject",
+ "source": "http://git.hoa-project.net/"
+ },
+ "require": {
+ "hoa/core": "~2.0"
+ },
+ "require-dev": {
+ "hoa/test": "~1.0"
+ },
+ "autoload": {
+ "psr-4": {
+ "Hoa\\Event\\": "."
+ }
+ },
+ "extra": {
+ "branch-alias": {
+ "dev-master": "0.x-dev"
+ }
+ }
+}