-
Notifications
You must be signed in to change notification settings - Fork 0
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
Robin de Graaf
committed
Aug 10, 2018
1 parent
1f93c1b
commit 419832c
Showing
21 changed files
with
1,839 additions
and
2 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,3 @@ | ||
.idea | ||
vendor | ||
coverage |
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 @@ | ||
language: php | ||
php: | ||
- '7.1' | ||
- '7.2' | ||
install: composer install | ||
script: vendor/bin/phpunit --verbose 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,6 @@ | ||
# Parable PHP DI | ||
|
||
### 0.1.0 | ||
|
||
_Changes:_ | ||
- First release. |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
dependencies: | ||
composer install \ | ||
--no-interaction \ | ||
--no-plugins \ | ||
--no-scripts | ||
|
||
tests: dependencies | ||
vendor/bin/phpunit --verbose tests | ||
|
||
coverage: dependencies | ||
rm -rf ./coverage | ||
vendor/bin/phpunit --coverage-html ./coverage tests | ||
|
||
tests-clean: | ||
vendor/bin/phpunit --verbose tests | ||
|
||
coverage-clean: | ||
rm -rf ./coverage | ||
vendor/bin/phpunit --coverage-html ./coverage 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,69 @@ | ||
# Parable DI Container | ||
|
||
[![Build Status](https://travis-ci.org/parable-php/event.svg?branch=master)](https://travis-ci.org/parable-php/event) | ||
[![Latest Stable Version](https://poser.pugx.org/parable-php/event/v/stable)](https://packagist.org/packages/parable-php/event) | ||
[![Latest Unstable Version](https://poser.pugx.org/parable-php/event/v/unstable)](https://packagist.org/packages/parable-php/event) | ||
[![License](https://poser.pugx.org/parable-php/event/license)](https://packagist.org/packages/parable-php/event) | ||
|
||
Parable Event is a straightforward event system that gets the job done. | ||
|
||
## Install | ||
|
||
Php 7.1+ and [composer](https://getcomposer.org) are required. | ||
|
||
```bash | ||
$ composer require parable-php/event | ||
``` | ||
|
||
## Usage | ||
|
||
Events are very simple. You add listeners to events (`string` values) and then trigger an update with those events. You | ||
can pass payloads into the update calls, which will get passed to all relevant listeners. | ||
|
||
```php | ||
use \Parable\Event\EventManager; | ||
|
||
$eventManager = new EventManager(); | ||
|
||
$eventManager->listen('event_number_one', function (string $event, string &$payload) { | ||
$payload .= '-updated!'; | ||
}); | ||
|
||
$payload = 'event'; | ||
|
||
$eventManager->trigger('event_number_one', $payload); | ||
|
||
echo $payload; | ||
|
||
// output: 'event-updated!' | ||
``` | ||
|
||
The above example handily shows how to make scalar values modifiable by defining the parameter to the callable as a | ||
reference. Passing objects is generally advisable, but sometimes it's the in-place alteration of string values you | ||
need. | ||
|
||
It's also possible to have a listener trigger on every single event update. | ||
|
||
```php | ||
$eventManager->listenAll(function (string $event, $payload) { | ||
echo $event . PHP_EOL; | ||
}); | ||
``` | ||
|
||
The above example would simply log all events being updated. This can be handy for debugging, but can also be handy | ||
to listen to a specific subset of events by matching the event, rather than adding a single listener to all individual | ||
events. | ||
|
||
## API | ||
|
||
- `listen(string $event, callable $$listener): void` - add listener to an event | ||
- `listenAll(string $event): void` - add listener for all events | ||
- `update(string $event): void` - trigger an update for an event | ||
|
||
## Contributing | ||
|
||
Any suggestions, bug reports or general feedback is welcome. Use github issues and pull requests, or find me over at [devvoh.com](https://devvoh.com). | ||
|
||
## License | ||
|
||
All Parable components are open-source software, licensed under the MIT license. |
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,31 @@ | ||
{ | ||
"name": "parable-php/events", | ||
"type": "library", | ||
"description": "Parable Events is a simple event system", | ||
"keywords": ["library", "event", "observer", "listener", "parable"], | ||
"homepage": "https://github.com/parable-php/event", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Robin de Graaf", | ||
"email": "[email protected]", | ||
"homepage": "https://devvoh.com" | ||
} | ||
], | ||
"require": { | ||
"php": ">=7.1" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^7.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Parable\\Event\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Parable\\Event\\Tests\\": "tests" | ||
} | ||
} | ||
} |
Oops, something went wrong.