Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bacinsky committed Mar 21, 2019
0 parents commit 528c82e
Show file tree
Hide file tree
Showing 30 changed files with 2,707 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .coveralls.yml
@@ -0,0 +1,2 @@
coverage_clover: tests/log/clover.xml
json_path: tests/log/coveralls-upload.json
8 changes: 8 additions & 0 deletions .gitattributes
@@ -0,0 +1,8 @@
tests export-ignore
.coveralls.yml export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.travis.yml export-ignore
.composer.lock export-ignore
phpcs.xml export-ignore
pre-commit export-ignore
16 changes: 16 additions & 0 deletions .gitignore
@@ -0,0 +1,16 @@
._*
.~lock.*
*.log
.buildpath
.DS_Store
.idea
.project
.settings
build
log
cache
vendor
composer.phar
nbproject
node_modules
!.gitignore
15 changes: 15 additions & 0 deletions .travis.yml
@@ -0,0 +1,15 @@
language: php
php:
- 7.1
before_install:
- composer self-update
install:
- composer install --no-interaction --prefer-source
- composer require php-coveralls/php-coveralls
script:
- composer build
after_failure:
# Prints tests *.actual files content
- for i in $(find ./tests -name \*.actual); do echo "--- $i"; cat $i; echo; echo; done
after_success:
- travis_retry php vendor/bin/php-coveralls -v
27 changes: 27 additions & 0 deletions LICENSE.md
@@ -0,0 +1,27 @@
Copyright (c) 2019, Webino, s. r. o. (https://webino.sk),
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 Webino 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 OWNER OR 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.
131 changes: 131 additions & 0 deletions README.md
@@ -0,0 +1,131 @@
# Webino Event Emitter

Event Emitter implementation.

[![Build Status](https://img.shields.io/travis/webino/event-emitter/master.svg?style=for-the-badge)](http://travis-ci.org/webino/event-emitter "Master Build Status")
[![Coverage Status](https://img.shields.io/coveralls/github/webino/event-emitter/master.svg?style=for-the-badge)](https://coveralls.io/github/webino/event-emitter?branch=master "Master Coverage Status")
[![Code Quality](https://img.shields.io/scrutinizer/g/webino/event-emitter/master.svg?style=for-the-badge)](https://scrutinizer-ci.com/g/webino/event-emitter/?branch=master "Master Code Quality")
[![Latest Stable Version](https://img.shields.io/github/tag/webino/event-emitter.svg?label=STABLE&style=for-the-badge)](https://packagist.org/packages/webino/event-emitter)


## Quick Use

Emitting an event:
```php
use Webino\EventEmitter;

$emitter = new EventEmitter;

// registering closure event handler
$emitter->on('example', function () {
return 'Hello';
});

// emitting custom event
$event = $emitter->emit('example');

/** @var \Webino\EventResults $results */
$results = $event->getResults();

echo $results;

// => Hello
```

Removing an event handler:
```php
use Webino\EventEmitter;

$emitter = new EventEmitter;

$handler = function () {
return 'Hello';
};

$emitter->on('example', $handler);

// remove handler for all events
$emitter->off($handler);

// remove all handlers for an event
$emitter->off(null, 'example');

// remove all handlers for all events
$emitter->off();
```

Emitting an event until:
```php
use Webino\EventEmitter;

$emitter = new EventEmitter;

$emitter->on('example', function () {
return 'Special';
});

$event = $emitter->emit('example', function ($result) {
// when result meets required condition
if ('Special' === $result) {
// stop propagation
return false;
}
// or continue
return true;
});
```

## Setup
[![PHP from Packagist](https://img.shields.io/packagist/php-v/webino/event-emitter.svg?style=for-the-badge)](https://php.net "Required PHP version")

```bash
composer require webino\event-emitter
```


## Development

[![Build Status](https://img.shields.io/travis/webino/event-emitter/develop.svg?style=for-the-badge)](http://travis-ci.org/webino/event-emitter "Develop Build Status")
[![Coverage Status](https://img.shields.io/coveralls/github/webino/event-emitter/develop.svg?style=for-the-badge)](https://coveralls.io/github/webino/event-emitter?branch=develop "Develop Coverage Status")
[![Code Quality](https://img.shields.io/scrutinizer/g/webino/event-emitter/develop.svg?style=for-the-badge)](https://scrutinizer-ci.com/g/webino/event-emitter/?branch=develop "Develop Code Quality")
[![Latest Unstable Version](https://img.shields.io/github/tag-pre/webino/event-emitter.svg?label=PREVIEW&style=for-the-badge)](https://packagist.org/packages/webino/event-emitter "Packagist")


Static analysis:
```bash
composer analyse
```

Coding style check:
```bash
composer check
```

Coding style fix:
```bash
composer fix
```

Testing:
```bash
composer test
```

Git pre-commit setup:
```bash
ln -s ../../pre-commit .git/hooks/pre-commit
```


## Addendum

[![License](https://img.shields.io/packagist/l/webino/event-emitter.svg?style=for-the-badge)](https://github.com/webino/event-emitter/blob/master/LICENSE.md "BSD-3-Clause License")
[![Total Downloads](https://img.shields.io/packagist/dt/webino/event-emitter.svg?style=for-the-badge)](https://packagist.org/packages/webino/event-emitter "Packagist")
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/webino/event-emitter.svg?style=for-the-badge)


Please, if you are interested in this library report any issues and don't hesitate to contribute.
We will appreciate any contributions on development of this library.

[![GitHub issues](https://img.shields.io/github/issues/webino/event-emitter.svg?style=for-the-badge)](https://github.com/webino/event-emitter/issues)
[![GitHub forks](https://img.shields.io/github/forks/webino/event-emitter.svg?label=Fork&style=for-the-badge)](https://github.com/webino/event-emitter)
54 changes: 54 additions & 0 deletions composer.json
@@ -0,0 +1,54 @@
{
"name": "webino/event-emitter",
"description": "Event Emitter implementation.",
"type": "library",
"license": "BSD-3-Clause",
"authors": [
{
"name": "Peter Bacinsky",
"email": "peter@bacinsky.sk"
}
],
"require": {
"php": "~7.1",
"webino/exceptions": "1.*"
},
"require-dev": {
"tracy/tracy": "2.*",
"nette/tester": "1.*",
"phpstan/phpstan": "0.*",
"squizlabs/php_codesniffer": "3.*"
},
"autoload": {
"psr-4": {
"Webino\\": [
"src"
]
}
},
"autoload-dev": {
"psr-4": {
"Webino\\": [
"tests/src"
]
}
},
"scripts": {
"check": "vendor/bin/phpcs --extensions=php,phpt",
"fix": "vendor/bin/phpcbf --extensions=php,phpt",
"analyse": "vendor/bin/phpstan analyse src --level max",
"test": "vendor/bin/tester -c tests/php.ini -d auto_prepend_file=$PWD/tests/bootstrap.php -l tests/log/test.log --coverage tests/log/clover.xml --coverage-src src",
"build": [
"@check",
"@analyse",
"@composer test tests"
]
},
"scripts-descriptions": {
"check": "Coding style check.",
"fix": "Coding style fix.",
"analyse": "Static analysis.",
"test": "Run tests.",
"build": "Automated build."
}
}

0 comments on commit 528c82e

Please sign in to comment.