scratch

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 114  →  ?path2? @ 115
/vendor/evenement/evenement/.gitignore
@@ -0,0 +1,2 @@
composer.lock
vendor
/vendor/evenement/evenement/.travis.yml
@@ -0,0 +1,10 @@
language: php
 
php:
- 5.4
 
before_script:
- wget http://getcomposer.org/composer.phar
- php composer.phar install
 
script: phpunit --coverage-text
/vendor/evenement/evenement/CHANGELOG.md
@@ -0,0 +1,8 @@
CHANGELOG
=========
 
* 2.0.0 (2012-11-02)
 
* Require PHP >=5.4.0
* Added EventEmitterTrait
* Removed EventEmitter2
/vendor/evenement/evenement/LICENSE
@@ -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.
/vendor/evenement/evenement/README.md
@@ -0,0 +1,83 @@
# Événement
 
Événement is a very simple event dispatching library for PHP.
 
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).
 
[![Build Status](https://secure.travis-ci.org/igorw/evenement.png?branch=master)](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": "2.0.*"
}
}
```
 
**Note:** The `2.0.*` version of Événement requires PHP 5.4. If you are
using PHP 5.3, please use the `1.0.*` version:
 
```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.created', function (User $user) use ($logger) {
$logger->log(sprintf("User '%s' was created.", $user->getLogin()));
});
```
 
### Emitting Events
 
```php
<?php
$emitter->emit('user.created', array($user));
```
 
Tests
-----
 
$ phpunit
 
License
-------
MIT, see LICENSE.
/vendor/evenement/evenement/composer.json
@@ -0,0 +1,25 @@
{
"name": "evenement/evenement",
"description": "Événement is a very simple event dispatching library for PHP",
"keywords": ["event-dispatcher", "event-emitter"],
"license": "MIT",
"authors": [
{
"name": "Igor Wiedler",
"email": "igor@wiedler.ch"
}
],
"require": {
"php": ">=5.4.0"
},
"autoload": {
"psr-0": {
"Evenement": "src"
}
},
"extra": {
"branch-alias": {
"dev-master": "2.0-dev"
}
}
}
/vendor/evenement/evenement/phpunit.xml.dist
@@ -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>
/vendor/evenement/evenement/src/Evenement/EventEmitter.php
@@ -0,0 +1,17 @@
<?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
{
use EventEmitterTrait;
}
/vendor/evenement/evenement/src/Evenement/EventEmitterInterface.php
@@ -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, callable $listener);
public function once($event, callable $listener);
public function removeListener($event, callable $listener);
public function removeAllListeners($event = null);
public function listeners($event);
public function emit($event, array $arguments = []);
}
/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php
@@ -0,0 +1,67 @@
<?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;
 
trait EventEmitterTrait
{
protected $listeners = [];
 
public function on($event, callable $listener)
{
if (!isset($this->listeners[$event])) {
$this->listeners[$event] = [];
}
 
$this->listeners[$event][] = $listener;
}
 
public function once($event, callable $listener)
{
$onceListener = function () use (&$onceListener, $event, $listener) {
$this->removeListener($event, $onceListener);
 
call_user_func_array($listener, func_get_args());
};
 
$this->on($event, $onceListener);
}
 
public function removeListener($event, callable $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 = [];
}
}
 
public function listeners($event)
{
return isset($this->listeners[$event]) ? $this->listeners[$event] : [];
}
 
public function emit($event, array $arguments = [])
{
foreach ($this->listeners($event) as $listener) {
call_user_func_array($listener, $arguments);
}
}
}
/vendor/evenement/evenement/tests/Evenement/Tests/EventEmitterTest.php
@@ -0,0 +1,235 @@
<?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\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', [$listener, 'onFoo']);
}
 
public function testAddListenerWithStaticMethod()
{
$this->emitter->on('bar', ['Evenement\Tests\Listener', 'onBar']);
}
 
public function testAddListenerWithInvalidListener()
{
try {
$this->emitter->on('foo', 'not a callable');
$this->fail();
} catch (\Exception $e) {
}
}
 
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 testOnceWithArguments()
{
$capturedArgs = [];
 
$this->emitter->once('foo', function ($a, $b) use (&$capturedArgs) {
$capturedArgs = array($a, $b);
});
 
$this->emitter->emit('foo', array('a', 'b'));
 
$this->assertSame(array('a', 'b'), $capturedArgs);
}
 
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', ['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', ['bar', 'baz']);
$this->assertSame(true, $listenerCalled);
}
 
public function testEmitWithNoListeners()
{
$this->emitter->emit('foo');
$this->emitter->emit('foo', ['bar']);
$this->emitter->emit('foo', ['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);
}
}
/vendor/evenement/evenement/tests/Evenement/Tests/Listener.php
@@ -0,0 +1,23 @@
<?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\Tests;
 
class Listener
{
public function onFoo()
{
}
 
public static function onBar()
{
}
}
/vendor/evenement/evenement/tests/bootstrap.php
@@ -0,0 +1,13 @@
<?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.
*/
 
$loader = require __DIR__.'/../vendor/autoload.php';
$loader->add('Evenement\Tests', __DIR__);