oihana/php-signals
Composer 安装命令:
composer require oihana/php-signals
包简介
The Oihana PHP Signals library
README 文档
README
A fast and flexible signal/slot implementation for event-driven programming.
📚 Documentation
Full project documentation is available at:
👉 https://bcommebois.github.io/oihana-php-signals
📦 Installation
Requires PHP 8.4+
Install via Composer:
composer require oihana/php-signals
✨ Features
Provides a robust observer pattern implementation with priority-based execution, auto-disconnect capability, and support for both callable functions and Receiver objects. It is ideal for event-driven architectures and decoupled communication between components.
- Priority-based receiver execution (higher priority executes first)
- Auto-disconnect for one-time listeners
- Type-safe receiver management
- Efficient sorting and execution order
- Supports both object receivers implementing
Receiverand PHP callables
🚀 Quick start
Basic usage with callables and Receiver objects.
use oihana\signals\Signal; use oihana\signals\Receiver; // Define a Receiver class class NotificationHandler implements Receiver { public function receive( mixed ...$values ) :void { echo 'Notification: ' . implode(', ', $values) . PHP_EOL; } } // Create receivers $logger = function( mixed ...$values ) { echo 'Log: ' . implode(', ', $values) . PHP_EOL; }; $handler = new NotificationHandler(); // Setup signal $signal = new Signal(); // Connect with different priorities $signal->connect( $logger , priority: 10 ); // Executes first $signal->connect( $handler , priority: 5 ); // Executes second // Emit values to all connected receivers $signal->emit( 'User logged in', 'user123' ); // One-time listener $signal->connect ( fn() => echo 'First emit only!' . PHP_EOL, autoDisconnect: true );
Note : WeakReferences are used for object receivers to allow proper garbage collection without preventing objects from being destroyed.
🧰 Usage
Advanced usage with priority and auto-disconnect
$signal = new Signal(); // High priority handler (executes first) $signal->connect ( fn($msg) => echo "URGENT: $msg" . PHP_EOL, priority: 100 ); // One-time handler (disconnects after first emit) $signal->connect ( fn($msg) => echo "Initialization: $msg" . PHP_EOL, priority: 50, autoDisconnect: true ); // Normal priority handler $signal->connect ( fn($msg) => echo "Info: $msg" . PHP_EOL ); // First emit - all three handlers execute $signal->emit('System started'); // Second emit - only two handlers execute (auto-disconnect removed one) $signal->emit('Processing data');
Running Unit Tests
To run all tests:
$ composer test
To run a specific test file:
$ composer test tests/oihana/signals/SignalTest.php
🤝 Contributing
Contributions are welcome! Whether you're fixing a bug, improving an existing feature, or proposing a new one, your help is appreciated.
Please feel free to:
- Report a bug: If you find a bug, please open an issue and provide as much detail as possible.
- Suggest an enhancement: Have an idea to make this library better? Open an issue to discuss it.
- Submit a pull request: Fork the repository, make your changes, and open a pull request. Please ensure all tests are passing before submitting.
You can find the issues page here: https://github.com/BcommeBois/oihana-php-core/issues
🗒️ Changelog
See CHANGELOG.md for notable changes.
License
This project is licensed under the Mozilla Public License 2.0 (MPL-2.0).
👤 About the author
- Author : Marc ALCARAZ (aka eKameleon)
- Mail : marc@ooop.fr
- Website : http://www.ooop.fr
🛠️ Generate the Documentation
We use phpDocumentor to generate the documentation into the ./docs folder.
🔗 Related packages
oihana/php-core– core helpers and utilities used by this library:https://github.com/BcommeBois/oihana-php-coreoihana/php-reflect– reflection and hydration utilities:https://github.com/BcommeBois/oihana-php-reflect
oihana/php-signals 适用场景与选型建议
oihana/php-signals 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 277 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 11 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「message」 「signals」 「notice」 「receiver」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 oihana/php-signals 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 oihana/php-signals 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 oihana/php-signals 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP AMQP Binding Library
Wireless Cross-Component Communication
Package secures Nette Framework signals against CSRF attack.
Privacy-first behavioral analytics foundation for Laravel applications
Filament admin dashboard for AIArmada Signals analytics
VEGAS, the opensource framework for PHP
统计信息
- 总下载量: 277
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 24
- 依赖项目数: 6
- 推荐数: 0
其他信息
- 授权协议: MPL-2.0
- 更新时间: 2025-11-12
