Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin de Graaf committed Aug 10, 2018
1 parent 1f93c1b commit 419832c
Show file tree
Hide file tree
Showing 21 changed files with 1,839 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea
vendor
coverage
6 changes: 6 additions & 0 deletions .travis.yml
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Parable PHP DI

### 0.1.0

_Changes:_
- First release.
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License
The MIT License (MIT)

Copyright (c) 2018 parable-php
Copyright (c) 2018 Robin de Graaf

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 Down
19 changes: 19 additions & 0 deletions Makefile
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
69 changes: 69 additions & 0 deletions README.md
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.
31 changes: 31 additions & 0 deletions composer.json
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"
}
}
}
Loading

0 comments on commit 419832c

Please sign in to comment.