Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase PHP requirement to 8.1 #88

Merged
merged 11 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Set the default behavior, in case people don't have core.autocrlf set.
* text eol=lf

/.github export-ignore
/doc export-ignore
/examples export-ignore
/tests export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/CHANGELOG.md export-ignore
/phpunit.xml.dist export-ignore
29 changes: 12 additions & 17 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
name: CI

on:
push:
pull_request:

jobs:
supported-versions-matrix:
name: Supported Versions Matrix
runs-on: ubuntu-latest
outputs:
version: ${{ steps.supported-versions-matrix.outputs.version }}
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- id: supported-versions-matrix
uses: WyriHaximus/github-action-composer-php-versions-in-range@v1

test:
name: Run Tests and Code Quality on PHP ${{ matrix.php }}
runs-on: ubuntu-latest
Expand All @@ -23,28 +26,20 @@ jobs:
php: ${{ fromJson(needs.supported-versions-matrix.outputs.version) }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP, extensions and composer with shivammathur/setup-php
uses: actions/checkout@v4

- name: Setup PHP and extensions with shivammathur/setup-php
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: mbstring, ctype, iconv, bcmath, filter, json
coverage: xdebug, pcov
tools: composer:v1
- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Get composer action hash
id: composer-action-hash
run: printf "::set-output name=hash::%s" $(echo -n "${{ matrix.composer }}" | sha512sum)
- name: Cache dependencies
uses: actions/cache@v2

- name: Setup Composer, install dependencies
uses: ramsey/composer-install@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-${{ steps.composer-action-hash.outputs.hash }}
- name: Install Composer dependencies
run: composer install --no-progress --no-interaction --no-suggest --optimize-autoloader --ansi
composer-options: "--optimize-autoloader"

- name: Test
run: |
./vendor/bin/phpunit --coverage-text
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
composer.lock
vendor
.phpunit.result.cache
.phpunit.cache
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
CHANGELOG
=========


ericsizemore marked this conversation as resolved.
Show resolved Hide resolved
* v3.0.1 (2017-07-23)

* Resolved regression introduced in once listeners in v3.0.0 [#49](https://github.com/igorw/evenement/pull/49)
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ It is very strongly inspired by the [EventEmitter](https://nodejs.org/api/events

The recommended way to install Événement is [through composer](http://getcomposer.org). By running the following command:

```bash
$ composer require evenement/evenement
```

## Usage

Expand All @@ -33,7 +35,7 @@ $emitter = new Evenement\EventEmitter();

```php
<?php
$emitter->on('user.created', function (User $user) use ($logger) {
$emitter->on('user.created', static function (User $user) use ($logger): void {
$logger->log(sprintf("User '%s' was created.", $user->getLogin()));
});
```
Expand All @@ -42,7 +44,7 @@ $emitter->on('user.created', function (User $user) use ($logger) {

```php
<?php
$emitter->removeListener('user.created', function (User $user) use ($logger) {
$emitter->removeListener('user.created', static function (User $user) use ($logger): void {
$logger->log(sprintf("User '%s' was created.", $user->getLogin()));
});
```
Expand All @@ -56,8 +58,9 @@ $emitter->emit('user.created', [$user]);

Tests
-----

```bash
$ ./vendor/bin/phpunit
```

License
-------
Expand Down
13 changes: 9 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
{
"name": "evenement/evenement",
"description": "Événement is a very simple event dispatching library for PHP",
"keywords": ["event-dispatcher", "event-emitter"],
"license": "MIT",
"keywords": [
"event-dispatcher",
"event-emitter"
],
"authors": [
{
"name": "Igor Wiedler",
"email": "[email protected]"
}
],
"require": {
"php": ">=7.0"
"php": ">=8.1"
},
"require-dev": {
"phpunit/phpunit": "^9 || ^6"
"phpunit/phpunit": "^10 || ^11"
},
"autoload": {
"psr-4": {
Expand All @@ -24,6 +27,8 @@
"psr-4": {
"Evenement\\Tests\\": "tests/"
},
"files": ["tests/functions.php"]
"files": [
"tests/functions.php"
]
}
}
22 changes: 11 additions & 11 deletions doc/01-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ define an interface that extends the emitter and implicitly defines certain
events to be emitted, or if you want to type hint an `EventEmitter` to be
passed to a method without coupling to the specific implementation.

## on($event, callable $listener)
## on(string $event, callable $listener): static;

Allows you to subscribe to an event.

Example:

```php
$emitter->on('user.created', function (User $user) use ($logger) {
$emitter->on('user.created', static function (User $user) use ($logger): void {
$logger->log(sprintf("User '%s' was created.", $user->getLogin()));
});
```
Expand All @@ -23,7 +23,7 @@ instead of the anonymous function:

```php
$loggerSubscriber = new LoggerSubscriber($logger);
$emitter->on('user.created', array($loggerSubscriber, 'onUserCreated'));
$emitter->on('user.created', [$loggerSubscriber, 'onUserCreated']);
```

This has the benefit that listener does not even need to know that the emitter
Expand All @@ -32,23 +32,23 @@ exists.
You can also accept more than one parameter for the listener:

```php
$emitter->on('numbers_added', function ($result, $a, $b) {});
$emitter->on('numbers_added', static function (int $result, int $a, int $b): void {});
```

## once($event, callable $listener)
## once(string $event, callable $listener): static;

Convenience method that adds a listener which is guaranteed to only be called
once.

Example:

```php
$conn->once('connected', function () use ($conn, $data) {
$conn->once('connected', static function () use ($conn, $data): void {
$conn->send($data);
});
```

## emit($event, array $arguments = [])
## emit(string $event, array $arguments = []): void;

Emit an event, which will call all listeners.

Expand All @@ -66,7 +66,7 @@ $result = $a + $b;
$emitter->emit('numbers_added', [$result, $a, $b]);
```

## listeners($event)
## listeners(?string $event = null): array;

Allows you to inspect the listeners attached to an event. Particularly useful
to check if there are any listeners at all.
Expand All @@ -75,16 +75,16 @@ Example:

```php
$e = new \RuntimeException('Everything is broken!');
if (0 === count($emitter->listeners('error'))) {
if (0 === \count($emitter->listeners('error'))) {
throw $e;
}
```

## removeListener($event, callable $listener)
## removeListener(string $event, callable $listener): void;

Remove a specific listener for a specific event.

## removeAllListeners($event = null)
## removeAllListeners(?string $event = null): void;

Remove all listeners for a specific event or all listeners all together. This
is useful for long-running processes, where you want to remove listeners in
Expand Down
16 changes: 8 additions & 8 deletions doc/02-plugin-system.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ A plugin class must implement the `PluginInterface`:
```php
interface PluginInterface
{
function attachEvents(EventEmitterInterface $emitter);
public function attachEvents(EventEmitterInterface $emitter): void;
}
```

Expand All @@ -38,9 +38,9 @@ emitter. For example:
```php
class FooPlugin implements PluginInterface
{
public function attachEvents(EventEmitterInterface $emitter)
public function attachEvents(EventEmitterInterface $emitter): void
{
$emitter->on('foo', function () {
$emitter->on('foo', static function (): void {
echo 'bar!';
});
}
Expand Down Expand Up @@ -76,7 +76,7 @@ In the code that creates the post, I'll insert the `post.create` event:
```php
class PostEvent
{
public $post;
public array $post;

public function __construct(array $post)
{
Expand All @@ -98,7 +98,7 @@ allowing listeners to change it.

The same thing for the `post.render` event:
```php
public function renderPostBody(array $post)
public function renderPostBody(array $post): string
{
$emitter = $this->emitter;

Expand Down Expand Up @@ -127,13 +127,13 @@ The `markdown` function represents a markdown to HTML converter.
```php
class MarkdownPlugin implements PluginInterface
{
public function attachEvents(EventEmitterInterface $emitter)
public function attachEvents(EventEmitterInterface $emitter): void
{
$emitter->on('post.create', function (PostEvent $event) {
$emitter->on('post.create', static function (PostEvent $event): void {
$event->post['format'] = 'markdown';
});

$emitter->on('post.render', function (PostEvent $event) {
$emitter->on('post.render', static function (PostEvent $event): void {
if (isset($event->post['format']) && 'markdown' === $event->post['format']) {
$event->post['body'] = markdown($event->post['body']);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/benchmark-emit-no-arguments.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

$emitter = new EventEmitter();

$emitter->on('event', function () {});
$emitter->on('event', static function (): void {});
ericsizemore marked this conversation as resolved.
Show resolved Hide resolved

$start = microtime(true);
for ($i = 0; $i < ITERATIONS; $i++) {
Expand Down
2 changes: 1 addition & 1 deletion examples/benchmark-emit-once.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
$emitter = new EventEmitter();

for ($i = 0; $i < ITERATIONS; $i++) {
$emitter->once('event', function ($a, $b, $c) {});
$emitter->once('event', static function (int $a, int $b, int $c): void {});
}

$start = microtime(true);
Expand Down
2 changes: 1 addition & 1 deletion examples/benchmark-emit-one-argument.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

$emitter = new EventEmitter();

$emitter->on('event', function ($a) {});
$emitter->on('event', static function (int $a): void {});

$start = microtime(true);
for ($i = 0; $i < ITERATIONS; $i++) {
Expand Down
2 changes: 1 addition & 1 deletion examples/benchmark-emit.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

$emitter = new EventEmitter();

$emitter->on('event', function ($a, $b, $c) {});
$emitter->on('event', static function (int $a, int $b, int $c): void {});

$start = microtime(true);
for ($i = 0; $i < ITERATIONS; $i++) {
Expand Down
2 changes: 1 addition & 1 deletion examples/benchmark-remove-listener-once.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

$listeners = [];
for ($i = 0; $i < ITERATIONS; $i++) {
$listeners[] = function ($a, $b, $c) {};
$listeners[] = static function (int $a, int $b, int $c): void {};
}

$start = microtime(true);
Expand Down
32 changes: 18 additions & 14 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
backupStaticAttributes="false"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
executionOrder="depends,defects"
requireCoverageMetadata="true"
beStrictAboutCoverageMetadata="true"
beStrictAboutOutputDuringTests="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
failOnRisky="true"
failOnWarning="true">
<testsuites>
<testsuite name="Evenement Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<source restrictNotices="true" restrictWarnings="true">
<include>
<directory>./src/</directory>
</whitelist>
</filter>
</include>
</source>
</phpunit>
Loading