From 0c85fcdc256bad679a56bc209557c6d66c0a8452 Mon Sep 17 00:00:00 2001
From: Ivan Zorin
Date: Fri, 20 Nov 2026 18:05:58 +0300
Subject: [PATCH 1/2] feat(events): migrate to Engine 9
---
.github/workflows/php.yml | 14 +++++++----
AGENTS.md | 4 ++--
CHANGELOG.md | 4 ++++
README.md | 43 +++++++++++++++++++++++++++++++++
README.ru.md | 42 ++++++++++++++++++++++++++++++++
composer.json | 6 ++++-
src/Bootstrap.php | 4 ++--
tests/engine_compatibility.php | 44 ++++++++++++++++++++++++++++++++++
8 files changed, 152 insertions(+), 9 deletions(-)
create mode 100644 README.ru.md
create mode 100644 tests/engine_compatibility.php
diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml
index d521c32..639673c 100644
--- a/.github/workflows/php.yml
+++ b/.github/workflows/php.yml
@@ -12,12 +12,13 @@ permissions:
jobs:
verify:
- name: PHP ${{ matrix.php }}
+ name: PHP ${{ matrix.php }} / ${{ matrix.dependencies }} dependencies
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
php: ['8.1', '8.5']
+ dependencies: ['latest', 'lowest']
steps:
- name: Checkout
uses: actions/checkout@v7
@@ -31,11 +32,16 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
coverage: none
- - name: Validate Composer manifest and lock
+ - name: Validate Composer manifest
run: composer validate --no-check-publish --no-interaction
- - name: Install locked dependencies
- run: composer install --prefer-dist --no-interaction --no-progress --no-scripts
+ - name: Resolve latest supported dependencies
+ if: matrix.dependencies == 'latest'
+ run: composer update --with-all-dependencies --no-interaction --no-progress --no-scripts
+
+ - name: Resolve lowest supported dependencies
+ if: matrix.dependencies == 'lowest'
+ run: composer update --with-all-dependencies --prefer-lowest --prefer-stable --no-interaction --no-progress --no-scripts
- name: Check PHP syntax
run: find . -path './vendor' -prune -o -path './.git' -prune -o -name '*.php' -type f -print0 | xargs -0 -n1 php -l
diff --git a/AGENTS.md b/AGENTS.md
index 3c6a007..3e98396 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -26,9 +26,9 @@
Опорные файлы: `README.md`, `.github/CONTRIBUTING.md`.
-`composer.json`: triangle/events; runtime "^8.1"; triangle/engine.
+`composer.json`: `triangle/events`; PHP `^8.1`; `triangle/engine ^9.0`; `composer test` runs `tests/engine_compatibility.php`.
-Именованных test/lint/build-скриптов в проверенных JSON-манифестах нет. Перед запуском выбери существующую команду из CI, конфигурации тестов или Makefile; не выдавай предполагаемую команду за проверенную.
+CI resolves latest and lowest supported dependency versions on PHP 8.1 and 8.5. It validates Composer metadata, runs PHP syntax checks, and executes the declared test script.
Команды выше найдены в манифестах, а не проверены запуском. Перед выполнением прочитай их реализацию, нужные переменные и внешние зависимости. Не запускай нагрузочные, сетевые, deploy/migration-задачи или полный train как обычный smoke test.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 053528d..5667af6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -24,6 +24,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+### Changed
+- Require Triangle Engine 9.x for the plugin configuration hooks used by event bootstrap.
+- Validate each converted event listener before registration.
+
### Planned
- Event broadcasting
- Async event processing
diff --git a/README.md b/README.md
index 5bf72cf..2192af7 100644
--- a/README.md
+++ b/README.md
@@ -19,3 +19,46 @@
+
+# Triangle Events
+
+Triangle Events registers application event listeners during Engine startup and provides an in-process dispatcher with exact-name and prefix listeners.
+
+## Requirements
+
+- PHP 8.1 or later
+- Triangle Engine 9.x
+
+Install the package with Composer:
+
+```sh
+composer require triangle/events
+```
+
+## Register and dispatch events
+
+```php
+use support\Events;
+
+Events::on('invoice.created', static function (array $invoice, string $event): void {
+ // Handle the created invoice.
+});
+
+Events::emit('invoice.created', ['id' => 42]);
+```
+
+Use a trailing `*` to register a prefix listener, for example `invoice.*`. Listeners receive the event payload followed by the event name. Dispatch is process-local; it does not provide durable queueing or cross-worker delivery.
+
+Listeners can also be declared in `config/event.php`:
+
+```php
+return [
+ 'invoice.created' => [
+ [App\Listeners\InvoiceCreated::class, 'handle'],
+ ],
+];
+```
+
+The Engine bootstrap loads application and plugin event configuration at startup. Engine 8 is not supported: this component uses the plugin configuration hooks introduced in Engine 9.
+
+Русская версия: [README.ru.md](README.ru.md).
diff --git a/README.ru.md b/README.ru.md
new file mode 100644
index 0000000..5b484ff
--- /dev/null
+++ b/README.ru.md
@@ -0,0 +1,42 @@
+# Triangle Events
+
+Triangle Events подключает обработчики событий при запуске Engine и предоставляет диспетчер внутри процесса с точными и префиксными именами событий.
+
+## Требования
+
+- PHP 8.1 или новее
+- Triangle Engine 9.x
+
+Установите пакет через Composer:
+
+```sh
+composer require triangle/events
+```
+
+## Регистрация и отправка событий
+
+```php
+use support\Events;
+
+Events::on('invoice.created', static function (array $invoice, string $event): void {
+ // Обработать созданный счёт.
+});
+
+Events::emit('invoice.created', ['id' => 42]);
+```
+
+Для регистрации обработчика на группу событий используйте `*` в конце имени, например `invoice.*`. Обработчик получает данные события, а затем его имя. Диспетчер работает в памяти процесса: он не сохраняет сообщения и не передаёт их другим workers.
+
+Обработчики также можно указать в `config/event.php`:
+
+```php
+return [
+ 'invoice.created' => [
+ [App\Listeners\InvoiceCreated::class, 'handle'],
+ ],
+];
+```
+
+Engine загружает конфигурацию приложения и плагинов во время запуска. Engine 8 не поддерживается: компонент использует хуки конфигурации плагинов, добавленные в Engine 9.
+
+English version: [README.md](README.md).
diff --git a/composer.json b/composer.json
index d0d4bf8..117b096 100644
--- a/composer.json
+++ b/composer.json
@@ -30,7 +30,11 @@
},
"require": {
"php": "^8.1",
- "triangle/engine": "^8.1"
+ "triangle/engine": "^9.0",
+ "psr/log": "^2.0 || ^3.0"
+ },
+ "scripts": {
+ "test": "php tests/engine_compatibility.php"
},
"suggest": {
},
diff --git a/src/Bootstrap.php b/src/Bootstrap.php
index d7bab5e..e25162b 100644
--- a/src/Bootstrap.php
+++ b/src/Bootstrap.php
@@ -63,7 +63,7 @@ public static function load(array $events): void
foreach ($callbacks as $callback) {
$callback = self::convertCallable($callback);
- if (is_callable($callbacks)) {
+ if (is_callable($callback)) {
Events::on($event, $callback);
} else {
throw new RuntimeException("Событие: $event => " . var_export($callback, true) . " не вызываемо");
@@ -87,4 +87,4 @@ protected static function convertCallable(mixed $callbacks): mixed
}
return $callbacks;
}
-}
\ No newline at end of file
+}
diff --git a/tests/engine_compatibility.php b/tests/engine_compatibility.php
new file mode 100644
index 0000000..2dac625
--- /dev/null
+++ b/tests/engine_compatibility.php
@@ -0,0 +1,44 @@
+
+ * @copyright Copyright © 2016-2026 Localzet Group. All rights reserved.
+ * @license https://www.gnu.org/licenses/agpl-3.0 GNU Affero General Public License v3.0
+ */
+
+require dirname(__DIR__) . '/vendor/autoload.php';
+
+use support\Events;
+use Triangle\Engine\BootstrapInterface;
+use Triangle\Engine\Plugin;
+use Triangle\Events\Bootstrap;
+
+if (!is_a(Bootstrap::class, BootstrapInterface::class, true)) {
+ throw new RuntimeException('The event bootstrap must implement the Engine bootstrap contract.');
+}
+
+if (!method_exists(Plugin::class, 'app_reduce') || !method_exists(Plugin::class, 'plugin_reduce')) {
+ throw new RuntimeException('The event bootstrap requires Engine plugin reduction hooks.');
+}
+
+$event = 'triangle.events.bootstrap.compatibility';
+$received = null;
+$payload = ['source' => 'test'];
+
+Bootstrap::load([
+ $event => [
+ static function (array $data) use (&$received): void {
+ $received = $data;
+ },
+ ],
+]);
+
+Events::emit($event, $payload);
+
+if ($received !== $payload) {
+ throw new RuntimeException('The configured event listener did not receive its payload.');
+}
+
+echo "TRIANGLE_EVENTS_ENGINE_COMPATIBILITY=ok\n";
From 0e10366af8ac62998e47d9999fcc1add2fd8099f Mon Sep 17 00:00:00 2001
From: Ivan Zorin
Date: Sat, 21 Nov 2026 03:16:44 +0300
Subject: [PATCH 2/2] docs: prepare versioned installation guidance
---
CHANGELOG.md | 6 ++++--
README.md | 2 +-
README.ru.md | 2 +-
3 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5667af6..81bff97 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,10 +22,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
---
-## [Unreleased]
+## [2.0.0] - Unreleased
+
+### Breaking
+- Require Triangle Engine 9.x for the plugin configuration hooks used by event bootstrap; Engine 8 is no longer supported.
### Changed
-- Require Triangle Engine 9.x for the plugin configuration hooks used by event bootstrap.
- Validate each converted event listener before registration.
### Planned
diff --git a/README.md b/README.md
index 2192af7..b22dc38 100644
--- a/README.md
+++ b/README.md
@@ -32,7 +32,7 @@ Triangle Events registers application event listeners during Engine startup and
Install the package with Composer:
```sh
-composer require triangle/events
+composer require triangle/events:^2.0
```
## Register and dispatch events
diff --git a/README.ru.md b/README.ru.md
index 5b484ff..215f6cd 100644
--- a/README.ru.md
+++ b/README.ru.md
@@ -10,7 +10,7 @@ Triangle Events подключает обработчики событий пр
Установите пакет через Composer:
```sh
-composer require triangle/events
+composer require triangle/events:^2.0
```
## Регистрация и отправка событий