Skip to content

Commit

Permalink
Start!
Browse files Browse the repository at this point in the history
  • Loading branch information
SmetDenis committed Jan 28, 2016
1 parent 0fcdb84 commit e04f3e5
Show file tree
Hide file tree
Showing 14 changed files with 832 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
languages:
PHP: true

exclude_paths:
- tests/*
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text eol=lf
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
build
vendor
resources
phpunit.xml
phpunit-*.xml
composer.lock
17 changes: 17 additions & 0 deletions .travis.yml
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
3 changes: 2 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016 JBZoo Content Construction Kit (CCK)
Copyright (c) 2015 JBZoo Content Construction Kit (CCK)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -19,3 +19,4 @@ 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.

103 changes: 101 additions & 2 deletions README.md
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
66 changes: 66 additions & 0 deletions composer.json
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"
}
}
34 changes: 34 additions & 0 deletions phpunit.xml.dist
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>
Loading

0 comments on commit e04f3e5

Please sign in to comment.