This commit is contained in:
Xes
2025-08-14 22:41:49 +02:00
parent 2de81ccc46
commit 8ce45119b6
39774 changed files with 4309466 additions and 0 deletions

2
vendor/evenement/evenement/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
composer.lock
vendor

12
vendor/evenement/evenement/.travis.yml vendored Normal file
View File

@@ -0,0 +1,12 @@
language: php
php:
- 5.3
- 5.4
- 5.5
before_script:
- wget http://getcomposer.org/composer.phar
- php composer.phar install
script: phpunit --coverage-text

19
vendor/evenement/evenement/LICENSE vendored Normal file
View File

@@ -0,0 +1,19 @@
Copyright (c) 2011 Igor Wiedler
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

74
vendor/evenement/evenement/README.md vendored Normal file
View File

@@ -0,0 +1,74 @@
# Événement
Événement is a very simple event dispatching library for PHP 5.3.
It has the same design goals as [Silex](http://silex-project.org) and
[Pimple](http://pimple-project.org), to empower the user while staying concise
and simple.
It is very strongly inspired by the EventEmitter API found in
[node.js](http://nodejs.org). It includes an implementation of
[EventEmitter2](https://github.com/hij1nx/EventEmitter2), that extends
the original EventEmitter.
[![Build Status](https://secure.travis-ci.org/igorw/evenement.png)](http://travis-ci.org/igorw/evenement)
## Fetch
The recommended way to install Événement is [through composer](http://getcomposer.org).
Just create a composer.json file for your project:
```JSON
{
"require": {
"evenement/evenement": "1.0.*"
}
}
```
And run these two commands to install it:
$ curl -s http://getcomposer.org/installer | php
$ php composer.phar install
Now you can add the autoloader, and you will have access to the library:
```php
<?php
require 'vendor/autoload.php';
```
## Usage
### Creating an Emitter
```php
<?php
$emitter = new Evenement\EventEmitter();
```
### Adding Listeners
```php
<?php
$emitter->on('user.create', function (User $user) use ($logger) {
$logger->log(sprintf("User '%s' was created.", $user->getLogin()));
});
```
### Emitting Events
```php
<?php
$emitter->emit('user.create', array($user));
```
Tests
-----
$ phpunit
License
-------
MIT, see LICENSE.

View File

@@ -0,0 +1,25 @@
{
"name": "evenement/evenement",
"description": "Événement is a very simple event dispatching library for PHP 5.3",
"keywords": ["event-dispatcher"],
"license": "MIT",
"authors": [
{
"name": "Igor Wiedler",
"email": "igor@wiedler.ch"
}
],
"require": {
"php": ">=5.3.0"
},
"autoload": {
"psr-0": {
"Evenement": "src"
}
},
"extra": {
"branch-alias": {
"dev-master": "2.0-dev"
}
}
}

View File

@@ -0,0 +1,28 @@
# Introduction
Événement is is French and means "event". The événement library aims to
provide a simple way of subscribing to events and notifying those subscribers
whenever an event occurs.
The API that it exposes is almost a direct port of the EventEmitter API found
in node.js. It also includes an "EventEmitter". There are some minor
differences however.
The EventEmitter is an implementation of the publish-subscribe pattern, which
is a generalized version of the observer pattern. The observer pattern
specifies an observable subject, which observers can register themselves to.
Once something interesting happens, the subject notifies its observers.
Pub/sub takes the same idea but encapsulates the observation logic inside a
separate object which manages all of its subscribers or listeners. Subscribers
are bound to an event name, and will only receive notifications of the events
they subscribed to.
**TLDR: What does evenement do, in short? It provides a mapping from event
names to a list of listener functions and triggers each listener for a given
event when it is emitted.**
Why do we do this, you ask? To achieve decoupling.
It allows you to design a system where the core will emit events, and modules
are able to subscribe to these events. And respond to them.

View File

@@ -0,0 +1,77 @@
# API
The API that événement exposes is defined by the
`Evenement\EventEmitterInterface`. The interface is useful if you want to
define an interface that extends the emitter and implicitly defines certain
events to be emitted, or if you want to type hint an `EventEmitter` to be
passed to a method without coupling to the specific implementation.
## on($event, callable $listener)
Allows you to subscribe to an event.
Example:
$emitter->on('user.created', function (User $user) use ($logger) {
$logger->log(sprintf("User '%s' was created.", $user->getLogin()));
});
Since the listener can be any callable, you could also use an instance method
instead of the anonymous function:
$loggerSubscriber = new LoggerSubscriber($logger);
$emitter->on('user.created', array($loggerSubscriber, 'onUserCreated'));
This has the benefit that listener does not even need to know that the emitter
exists.
You can also accept more than one parameter for the listener:
$emitter->on('numbers_added', function ($result, $a, $b) {});
## once($event, callable $listener)
Convenience method that adds a listener which is guaranteed to only be called
once.
Example:
$conn->once('connected', function () use ($conn, $data) {
$conn->send($data);
});
## emit($event, array $arguments = [])
Emit an event, which will call all listeners.
Example:
$conn->emit('data', array($data));
The second argument to emit is an array of listener arguments. This is how you
specify more args:
$result = $a + $b;
$emitter->emit('numbers_added', array($result, $a, $b));
## listeners($event)
Allows you to inspect the listeners attached to an event. Particularly useful
to check if there are any listeners at all.
Example:
$e = new \RuntimeException('Everything is broken!');
if (0 === count($emitter->listeners('error'))) {
throw $e;
}
## removeListener($event, callable $listener)
Remove a specific listener for a specific event.
## removeAllListeners($event = null)
Remove all listeners for a specific event or all listeners alltogether. This
is useful for long-running processes, where you want to remove listeners in
order to allow them to get garbage collected.

View File

@@ -0,0 +1,147 @@
# Example: Plugin system
In this example I will show you how to create a generic plugin system with
événement where plugins can alter the behaviour of the app. The app is a blog.
Boring, I know. By using the EventEmitter it will be easy to extend this blog
with additional functionality without modifying the core system.
The blog is quite basic. Users are able to create blog posts when they log in.
The users are stored in a static config file, so there is no sign up process.
Once logged in they get a "new post" link which gives them a form where they
can create a new blog post with plain HTML. That will store the post in a
document database. The index lists all blog post titles by date descending.
Clicking on the post title will take you to the full post.
## Plugin structure
The goal of the plugin system is to allow features to be added to the blog
without modifying any core files of the blog.
The plugins are managed through a config file, `plugins.json`. This JSON file
contains a JSON-encoded list of class-names for plugin classes. This allows
you to enable and disable plugins in a central location. The initial
`plugins.json` is just an empty array:
[]
A plugin class must implement the `PluginInterface`:
interface PluginInterface
{
function attachEvents(EventEmitterInterface $emitter);
}
The `attachEvents` method allows the plugin to attach any events to the
emitter. For example:
class FooPlugin implements PluginInterface
{
public function attachEvents(EventEmitterInterface $emitter)
{
$emitter->on('foo', function () {
echo 'bar!';
});
}
}
The blog system creates an emitter instance and loads the plugins:
$emitter = new EventEmitter();
$pluginClasses = json_decode(file_get_contents('plugins.json'), true);
foreach ($pluginClasses as $pluginClass) {
$plugin = new $pluginClass();
$pluginClass->attachEvents($emitter);
}
This is the base system. There are no plugins yet, and there are no events yet
either. That's because I don't know which extension points will be needed. I
will add them on demand.
## Feature: Markdown
Writing blog posts in HTML sucks! Wouldn't it be great if I could write them
in a nice format such as markdown, and have that be converted to HTML for me?
This feature will need two extension points. I need to be able to mark posts
as markdown, and I need to be able to hook into the rendering of the post body
and convert it from markdown to HTML. So the blog needs two new events:
`post.create` and `post.render`.
In the code that creates the post, I'll insert the `post.create` event:
class PostEvent
{
public $post;
public function __construct(array $post)
{
$this->post = $post;
}
}
$post = createPostFromRequest($_POST);
$event = new PostEvent($post);
$emitter->emit('post.create', array($event));
$post = $event->post;
$db->save('post', $post);
This shows that you can wrap a value in an event object to make it mutable,
allowing listeners to change it.
The same thing for the `post.render` event:
public function renderPostBody(array $post)
{
$emitter = $this->emitter;
$event = new PostEvent($post);
$emitter->emit('post.render', array($event));
$post = $event->post;
return $post['body'];
}
<h1><?= $post['title'] %></h1>
<p><?= renderPostBody($post) %></p>
Ok, the events are in place. It's time to create the first plugin, woohoo! I
will call this the `MarkdownPlugin`, so here's `plugins.json`:
[
"MarkdownPlugin"
]
The `MarkdownPlugin` class will be autoloaded, so I don't have to worry about
including any files. I just have to worry about implementing the plugin class.
The `markdown` function represents a markdown to HTML converter.
class MarkdownPlugin implements PluginInterface
{
public function attachEvents(EventEmitterInterface $emitter)
{
$emitter->on('post.create', function (PostEvent $event) {
$event->post['format'] = 'markdown';
});
$emitter->on('post.render', function (PostEvent $event) {
if (isset($event->post['format']) && 'markdown' === $event->post['format']) {
$event->post['body'] = markdown($event->post['body']);
}
});
}
}
There you go, the blog now renders posts as markdown. But all of the previous
posts before the addition of the markdown plugin are still rendered correctly
as raw HTML.
## Feature: Comments
TODO
## Feature: Comment spam control
TODO

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="tests/bootstrap.php"
>
<testsuites>
<testsuite name="Evenement Test Suite">
<directory>./tests/Evenement/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./src/</directory>
</whitelist>
</filter>
</phpunit>

View File

@@ -0,0 +1,75 @@
<?php
/*
* This file is part of Evenement.
*
* (c) Igor Wiedler <igor@wiedler.ch>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Evenement;
class EventEmitter implements EventEmitterInterface
{
protected $listeners = array();
public function on($event, $listener)
{
if (!\is_callable($listener)) {
throw new \InvalidArgumentException('The provided listener was not a valid callable.');
}
if (!isset($this->listeners[$event])) {
$this->listeners[$event] = array();
}
$this->listeners[$event][] = $listener;
return $this;
}
public function once($event, $listener)
{
$that = $this;
$onceListener = function () use ($that, &$onceListener, $event, $listener) {
$that->removeListener($event, $onceListener);
\call_user_func_array($listener, \func_get_args());
};
$this->on($event, $onceListener);
}
public function removeListener($event, $listener)
{
if (isset($this->listeners[$event])) {
if (false !== $index = \array_search($listener, $this->listeners[$event], true)) {
unset($this->listeners[$event][$index]);
}
}
}
public function removeAllListeners($event = null)
{
if ($event !== null) {
unset($this->listeners[$event]);
} else {
$this->listeners = array();
}
}
public function listeners($event)
{
return isset($this->listeners[$event]) ? $this->listeners[$event] : array();
}
public function emit($event, array $arguments = array())
{
foreach ($this->listeners($event) as $listener) {
\call_user_func_array($listener, $arguments);
}
}
}

View File

@@ -0,0 +1,114 @@
<?php
/*
* This file is part of Evenement.
*
* (c) Igor Wiedler <igor@wiedler.ch>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Evenement;
class EventEmitter2 extends EventEmitter
{
protected $options;
protected $anyListeners = array();
public function __construct(array $options = array())
{
$this->options = \array_merge(array(
'delimiter' => '.',
), $options);
}
public function onAny($listener)
{
$this->anyListeners[] = $listener;
}
public function offAny($listener)
{
if (false !== $index = \array_search($listener, $this->anyListeners, true)) {
unset($this->anyListeners[$index]);
}
}
public function many($event, $timesToListen, $listener)
{
$that = $this;
$timesListened = 0;
if ($timesToListen == 0) {
return;
}
if ($timesToListen < 0) {
throw new \OutOfRangeException('You cannot listen less than zero times.');
}
$manyListener = function () use ($that, &$timesListened, &$manyListener, $event, $timesToListen, $listener) {
if (++$timesListened == $timesToListen) {
$that->removeListener($event, $manyListener);
}
\call_user_func_array($listener, \func_get_args());
};
$this->on($event, $manyListener);
}
public function emit($event, array $arguments = array())
{
foreach ($this->anyListeners as $listener) {
\call_user_func_array($listener, $arguments);
}
parent::emit($event, $arguments);
}
public function listeners($event)
{
$matchedListeners = array();
foreach ($this->listeners as $name => $listeners) {
foreach ($listeners as $listener) {
if ($this->matchEventName($event, $name)) {
$matchedListeners[] = $listener;
}
}
}
return $matchedListeners;
}
protected function matchEventName($matchPattern, $eventName)
{
$patternParts = \explode($this->options['delimiter'], $matchPattern);
$nameParts = \explode($this->options['delimiter'], $eventName);
if (\count($patternParts) != \count($nameParts)) {
return false;
}
$size = \min(\count($patternParts), \count($nameParts));
for ($i = 0; $i < $size; $i++) {
$patternPart = $patternParts[$i];
$namePart = $nameParts[$i];
if ('*' === $patternPart || '*' === $namePart) {
continue;
}
if ($namePart === $patternPart) {
continue;
}
return false;
}
return true;
}
}

View File

@@ -0,0 +1,22 @@
<?php
/*
* This file is part of Evenement.
*
* (c) Igor Wiedler <igor@wiedler.ch>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Evenement;
interface EventEmitterInterface
{
public function on($event, $listener);
public function once($event, $listener);
public function removeListener($event, $listener);
public function removeAllListeners($event = null);
public function listeners($event);
public function emit($event, array $arguments = array());
}

View File

@@ -0,0 +1,160 @@
<?php
/*
* This file is part of Evenement.
*
* Copyright (c) 2011 Igor Wiedler
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
namespace Evenement\Tests;
use Evenement\EventEmitter2;
class EventEmitter2Test extends \PHPUnit_Framework_TestCase
{
private $emitter;
public function setUp()
{
$this->emitter = new EventEmitter2();
}
// matching tests from
// test/wildcardEvents/addListener.js
public function testWildcardMatching7()
{
$listenerCalled = 0;
$listener = function () use (&$listenerCalled) {
$listenerCalled++;
};
$this->emitter->on('*.test', $listener);
$this->emitter->on('*.*', $listener);
$this->emitter->on('*', $listener);
$this->emitter->emit('other.emit');
$this->emitter->emit('foo.test');
$this->assertSame(3, $listenerCalled);
}
public function testWildcardMatching8()
{
$listenerCalled = 0;
$listener = function () use (&$listenerCalled) {
$listenerCalled++;
};
$this->emitter->on('foo.test', $listener);
$this->emitter->on('*.*', $listener);
$this->emitter->on('*', $listener);
$this->emitter->emit('*.*');
$this->emitter->emit('foo.test');
$this->emitter->emit('*');
$this->assertSame(5, $listenerCalled);
}
public function testOnAny()
{
$this->emitter->onAny(function () {});
}
public function testOnAnyWithEmit()
{
$listenerCalled = 0;
$this->emitter->onAny(function () use (&$listenerCalled) {
$listenerCalled++;
});
$this->assertSame(0, $listenerCalled);
$this->emitter->emit('foo');
$this->assertSame(1, $listenerCalled);
$this->emitter->emit('bar');
$this->assertSame(2, $listenerCalled);
}
public function testoffAnyWithEmit()
{
$listenerCalled = 0;
$listener = function () use (&$listenerCalled) {
$listenerCalled++;
};
$this->emitter->onAny($listener);
$this->emitter->offAny($listener);
$this->assertSame(0, $listenerCalled);
$this->emitter->emit('foo');
$this->assertSame(0, $listenerCalled);
}
/**
* @dataProvider provideMany
*/
public function testMany($amount)
{
$listenerCalled = 0;
$this->emitter->many('foo', $amount, function () use (&$listenerCalled) {
$listenerCalled++;
});
for ($i = 0; $i < $amount; $i++) {
$this->assertSame($i, $listenerCalled);
$this->emitter->emit('foo');
}
$this->emitter->emit('foo');
$this->assertSame($amount, $listenerCalled);
}
public function provideMany()
{
return array(
array(0),
array(1),
array(2),
array(3),
array(4),
array(400),
);
}
/**
* @expectedException OutOfRangeException
*/
public function testManyWithLessThanZeroTtl()
{
$this->emitter->many('foo', -1, function () {});
$this->emitter->emit('foo');
}
}

View File

@@ -0,0 +1,236 @@
<?php
/*
* This file is part of Evenement.
*
* Copyright (c) 2011 Igor Wiedler
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
namespace Evenement\Tests;
use Evenement\EventEmitter;
class EventEmitterTest extends \PHPUnit_Framework_TestCase
{
private $emitter;
public function setUp()
{
$this->emitter = new EventEmitter();
}
public function testAddListenerWithLambda()
{
$this->emitter->on('foo', function () {});
}
public function testAddListenerWithMethod()
{
$listener = new Listener();
$this->emitter->on('foo', array($listener, 'onFoo'));
}
public function testAddListenerWithStaticMethod()
{
$this->emitter->on('bar', array('Evenement\Tests\Listener', 'onBar'));
}
/**
* @expectedException InvalidArgumentException
*/
public function testAddListenerWithInvalidListener()
{
$this->emitter->on('foo', 'not a callable');
}
public function testOnce()
{
$listenerCalled = 0;
$this->emitter->once('foo', function () use (&$listenerCalled) {
$listenerCalled++;
});
$this->assertSame(0, $listenerCalled);
$this->emitter->emit('foo');
$this->assertSame(1, $listenerCalled);
$this->emitter->emit('foo');
$this->assertSame(1, $listenerCalled);
}
public function testEmitWithoutArguments()
{
$listenerCalled = false;
$this->emitter->on('foo', function () use (&$listenerCalled) {
$listenerCalled = true;
});
$this->assertSame(false, $listenerCalled);
$this->emitter->emit('foo');
$this->assertSame(true, $listenerCalled);
}
public function testEmitWithOneArgument()
{
$test = $this;
$listenerCalled = false;
$this->emitter->on('foo', function ($value) use (&$listenerCalled, $test) {
$listenerCalled = true;
$test->assertSame('bar', $value);
});
$this->assertSame(false, $listenerCalled);
$this->emitter->emit('foo', array('bar'));
$this->assertSame(true, $listenerCalled);
}
public function testEmitWithTwoArguments()
{
$test = $this;
$listenerCalled = false;
$this->emitter->on('foo', function ($arg1, $arg2) use (&$listenerCalled, $test) {
$listenerCalled = true;
$test->assertSame('bar', $arg1);
$test->assertSame('baz', $arg2);
});
$this->assertSame(false, $listenerCalled);
$this->emitter->emit('foo', array('bar', 'baz'));
$this->assertSame(true, $listenerCalled);
}
public function testEmitWithNoListeners()
{
$this->emitter->emit('foo');
$this->emitter->emit('foo', array('bar'));
$this->emitter->emit('foo', array('bar', 'baz'));
}
public function testEmitWithTwoListeners()
{
$listenersCalled = 0;
$this->emitter->on('foo', function () use (&$listenersCalled) {
$listenersCalled++;
});
$this->emitter->on('foo', function () use (&$listenersCalled) {
$listenersCalled++;
});
$this->assertSame(0, $listenersCalled);
$this->emitter->emit('foo');
$this->assertSame(2, $listenersCalled);
}
public function testRemoveListenerMatching()
{
$listenersCalled = 0;
$listener = function () use (&$listenersCalled) {
$listenersCalled++;
};
$this->emitter->on('foo', $listener);
$this->emitter->removeListener('foo', $listener);
$this->assertSame(0, $listenersCalled);
$this->emitter->emit('foo');
$this->assertSame(0, $listenersCalled);
}
public function testRemoveListenerNotMatching()
{
$listenersCalled = 0;
$listener = function () use (&$listenersCalled) {
$listenersCalled++;
};
$this->emitter->on('foo', $listener);
$this->emitter->removeListener('bar', $listener);
$this->assertSame(0, $listenersCalled);
$this->emitter->emit('foo');
$this->assertSame(1, $listenersCalled);
}
public function testRemoveAllListenersMatching()
{
$listenersCalled = 0;
$this->emitter->on('foo', function () use (&$listenersCalled) {
$listenersCalled++;
});
$this->emitter->removeAllListeners('foo');
$this->assertSame(0, $listenersCalled);
$this->emitter->emit('foo');
$this->assertSame(0, $listenersCalled);
}
public function testRemoveAllListenersNotMatching()
{
$listenersCalled = 0;
$this->emitter->on('foo', function () use (&$listenersCalled) {
$listenersCalled++;
});
$this->emitter->removeAllListeners('bar');
$this->assertSame(0, $listenersCalled);
$this->emitter->emit('foo');
$this->assertSame(1, $listenersCalled);
}
public function testRemoveAllListenersWithoutArguments()
{
$listenersCalled = 0;
$this->emitter->on('foo', function () use (&$listenersCalled) {
$listenersCalled++;
});
$this->emitter->on('bar', function () use (&$listenersCalled) {
$listenersCalled++;
});
$this->emitter->removeAllListeners();
$this->assertSame(0, $listenersCalled);
$this->emitter->emit('foo');
$this->emitter->emit('bar');
$this->assertSame(0, $listenersCalled);
}
}

View File

@@ -0,0 +1,38 @@
<?php
/*
* This file is part of Evenement.
*
* Copyright (c) 2011 Igor Wiedler
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
namespace Evenement\Tests;
class Listener
{
public function onFoo()
{
}
public static function onBar()
{
}
}

View File

@@ -0,0 +1,28 @@
<?php
/*
* This file is part of Evenement.
*
* Copyright (c) 2011 Igor Wiedler
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
$loader = require __DIR__.'/../vendor/autoload.php';
$loader->add('Evenement\Tests', __DIR__);