-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
SmetDenis
committed
Jan 28, 2016
1 parent
0fcdb84
commit e04f3e5
Showing
14 changed files
with
832 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
languages: | ||
PHP: true | ||
|
||
exclude_paths: | ||
- tests/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* text eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
build | ||
vendor | ||
resources | ||
phpunit.xml | ||
phpunit-*.xml | ||
composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
language: php | ||
|
||
php: | ||
- 5.4 | ||
- 5.5 | ||
- 5.6 | ||
- 7.0 | ||
|
||
matrix: | ||
fast_finish: true | ||
|
||
script: | ||
- composer update-all | ||
- composer test | ||
|
||
after_script: | ||
- composer coveralls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,101 @@ | ||
# Event | ||
Library for lightweight event-based programming | ||
# JBZoo Event [![Build Status](https://travis-ci.org/JBZoo/Event.svg?branch=master)](https://travis-ci.org/JBZoo/Event) [![Coverage Status](https://coveralls.io/repos/JBZoo/Event/badge.svg?branch=master&service=github)](https://coveralls.io/github/JBZoo/Event?branch=master) | ||
|
||
#### PHP Library for event-based development (fork from [sabre/event](https://github.com/fruux/sabre-event)) | ||
|
||
[![License](https://poser.pugx.org/JBZoo/Event/license)](https://packagist.org/packages/JBZoo/Event) [![Latest Stable Version](https://poser.pugx.org/JBZoo/Event/v/stable)](https://packagist.org/packages/JBZoo/Event) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/JBZoo/Event/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/JBZoo/Event/?branch=master) | ||
|
||
The EventEmitter is a simple pattern that allows you to create an object that emits events, and allow you to listen to those events. | ||
|
||
### Simple example | ||
|
||
```php | ||
require_once './vendor/autoload.php'; // composer autoload.php | ||
|
||
// Get needed classes | ||
use JBZoo\Event\EventManager; | ||
|
||
$eManager = new EventManager(); | ||
|
||
// Simple | ||
$eManager->on('create', function () { | ||
echo "Something action"; | ||
}); | ||
|
||
// JUST DO IT | ||
$eManager->trigger('create'); | ||
``` | ||
|
||
|
||
### Set priority | ||
By supplying a priority, you are ensured that subscribers are handled in a specific order. The default priority is EventManager::MID. | ||
Anything below that will be triggered earlier, anything higher later. | ||
If there's two subscribers with the same priority, they will execute in an undefined, but deterministic order. | ||
```php | ||
// Run it first | ||
$eManager->on('create', function () { | ||
echo "Something high priority action"; | ||
}, EventManager::HIGH); | ||
|
||
// Run it latest | ||
$eManager->on('create', function () { | ||
echo "Something another action"; | ||
}, EventManager::LOW); | ||
|
||
// Custom index | ||
$eManager->on('create', function () { | ||
echo "Something action"; | ||
}, 42); | ||
|
||
// don't care... | ||
$eManager->on('create', function () { | ||
echo "Something action"; | ||
}); | ||
``` | ||
|
||
### Types of Callback | ||
All default PHP callbacks are supported, so closures are not required. | ||
```php | ||
$eManager->on('create', function(){ /* ... */ }); // Custom function | ||
$eManager->on('create', 'myFunction'); // Custom function name | ||
$eManager->on('create', ['myClass', 'myMethod']); // Static function | ||
$eManager->on('create', [$object, 'Method']); // Method of instance | ||
``` | ||
|
||
|
||
### Cancel queue of events | ||
```php | ||
use JBZoo\Event\Exception; | ||
|
||
$eManager->on('create', function () { | ||
throw new Exception(); // Special exception for JBZoo/Event | ||
}); | ||
``` | ||
|
||
|
||
### Passing arguments | ||
Arguments can be passed as an array. | ||
```php | ||
$eManager->on('create', function ($entityId) { | ||
echo "An entity with id ", $entityId, " just got created.\n"; | ||
}); | ||
$entityId = 5; | ||
$eManager->trigger('create', [$entityId]); | ||
``` | ||
|
||
Because you cannot really do anything with the return value of a listener, you can pass arguments by reference to communicate between listeners and back to the emitter. | ||
```php | ||
$eManager->on('create', function ($entityId, &$warnings) { | ||
echo "An entity with id ", $entityId, " just got created.\n"; | ||
$warnings[] = "Something bad may or may not have happened.\n"; | ||
}); | ||
$warnings = []; | ||
$eventEmitter->trigger('create', [$entityId, &$warnings]); | ||
``` | ||
|
||
### Namespaces | ||
... coming soon :) | ||
|
||
|
||
### License | ||
|
||
MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
{ | ||
"name" : "jbzoo/event", | ||
"type" : "library", | ||
"description" : "Library for event-based development", | ||
"license" : "MIT", | ||
"keywords" : ["JBZoo", "Events", "EventManager", "Listener", "Hook", "Signal"], | ||
"minimum-stability" : "stable", | ||
"authors" : [ | ||
{ | ||
"name" : "SmetDenis", | ||
"email" : "denis@jbzoo.com", | ||
"role" : "lead" | ||
}, | ||
{ | ||
"name" : "Evert Pot", | ||
"email" : "me@evertpot.com", | ||
"homepage" : "http://sabre.io/event/" | ||
} | ||
], | ||
"require" : { | ||
"php" : ">=5.4" | ||
}, | ||
"require-dev" : { | ||
"jbzoo/phpunit" : "^1.0" | ||
}, | ||
"autoload" : { | ||
"psr-4" : { | ||
"JBZoo\\Event\\" : "src" | ||
} | ||
}, | ||
"extra" : { | ||
"branch-alias" : { | ||
"dev-master" : "1.x-dev" | ||
} | ||
}, | ||
"config" : { | ||
"optimize-autoloader" : true | ||
}, | ||
"scripts" : { | ||
"test" : [ | ||
"@manifest", | ||
"@autoload", | ||
"@phpunit", | ||
"@phpmd", | ||
"@phpcs", | ||
"@phpcpd", | ||
"@phploc" | ||
], | ||
"update-all" : [ | ||
"composer self-update --no-interaction", | ||
"composer update --no-interaction --optimize-autoloader" | ||
], | ||
"git-reset" : "git reset --hard", | ||
"manifest" : "composer validate --no-interaction", | ||
"autoload" : "composer dump-autoload --optimize --no-interaction", | ||
"phpunit" : "php ./vendor/phpunit/phpunit/phpunit --configuration ./phpunit.xml.dist", | ||
"phpmd" : "php ./vendor/phpmd/phpmd/src/bin/phpmd ./src text ./vendor/jbzoo/misc/phpmd/jbzoo.xml --verbose", | ||
"phpcs" : "php ./vendor/squizlabs/php_codesniffer/scripts/phpcs ./src --standard=./vendor/jbzoo/misc/phpcs/JBZoo/ruleset.xml --report=full", | ||
"phpcpd" : "php ./vendor/sebastian/phpcpd/phpcpd ./src --verbose", | ||
"phploc" : "php ./vendor/phploc/phploc/phploc ./src --verbose", | ||
"coveralls" : "php ./vendor/satooshi/php-coveralls/bin/coveralls --verbose" | ||
}, | ||
"support" : { | ||
"issues" : "https://github.com/JBZoo/Event/issues" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<phpunit bootstrap="tests/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
syntaxCheck="true" | ||
stopOnError="true" | ||
stopOnFailure="true" | ||
stopOnIncomplete="true" | ||
stopOnSkipped="false" | ||
stopOnRisky="false" | ||
verbose="false" | ||
> | ||
|
||
<testsuites> | ||
<testsuite name="General"> | ||
<directory suffix="Test.php">./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<filter> | ||
<whitelist processUncoveredFilesFromWhitelist="true"> | ||
<directory suffix=".php">src</directory> | ||
</whitelist> | ||
</filter> | ||
|
||
<logging> | ||
<log type="coverage-clover" target="build/logs/clover.xml"/> | ||
<log type="coverage-text" target="php://stdout" showUncoveredFiles="false" showOnlySummary="true"/> | ||
</logging> | ||
|
||
</phpunit> |
Oops, something went wrong.