rcs_us / framework_core
Qt的信号/槽的PHP实现。此版本适用于5.3+和7+,因为有命名空间。请查看其他版本以获取不带命名空间的旧版本。
7.1.12
2018-01-07 15:15 UTC
Requires
- php: ^5.3 || ^7.0
This package is not auto-updated.
Last update: 2024-09-25 08:47:10 UTC
README
基于Qt对信号/槽的实现(非异步)
概述
此版本适用于5.3+和7+,因为有命名空间。请查看其他版本以获取不带命名空间的旧版本。
与Qt的信号/槽一样,此包被构建得非常轻量级,并与不最初依赖于它的现有应用程序很好地配合工作。
添加此包的功能很简单
- 在您现有的类中扩展RCS_Core_Object。
- 为您的类添加文档注释中的@signal声明。
- 为您的函数添加文档注释中的@slot声明。
示例
/** * @signal signalWithNoArguments * @signal signalWithOneArgument * ^-- This is required. You will declare all of your signals this way */ class Test_Signal_Class extends \RCS\Core\Object { /** * */ public function testFunctionEmittingSignalWithNoArguments () { $this->emit( "signalWithNoArguments" ); } /** * */ public function testFunctionEmittingSignalWithOneArgument () { $this->emit( "signalWithOneArgument", new Test_Model_Class() ); } } class Test_Slot_Class extends \RCS\Core\Object { /** * * @slot * ^-- This is required to declare the function as a slot */ public function testSlotForSignalWithNoArguments () { print "Got to " . __METHOD__ . "<br />\n"; } /** * * @slot * ^-- This is required to declare the function as a slot */ public function testSlotForSignalWithOneArgument ( Test_Model_Class $testModelClass ) { // var_dump(debug_backtrace()); print "Got to " . __METHOD__ . "<br />\n"; print_r($testModelClass); } } class Test_Model_Class {} $testSignalClass = new Test_Signal_Class(); $testSlotClass = new Test_Slot_Class(); // This is the ideal way to implement the library \RCS\Core\Object::connect($testSignalClass, "signalWithNoArguments", $testSlotClass, "testSlotForSignalWithNoArguments"); \RCS\Core\Object::connect($testSignalClass, "signalWithOneArgument", $testSlotClass, "testSlotForSignalWithOneArgument"); // This can be used in cases where the original code implementation was done very poorly, // or possibly encoded into a package such as Zend Guard or a PHP extension where you can't access the source directly \RCS\Core\Object::connectByName("Test_Signal_Class", "signalWithOneArgument", $testSlotClass, "testSlotForSignalWithOneArgument"); // This has just one connection $testSignalClass->testFunctionEmittingSignalWithNoArguments(); // This has two connections $testSignalClass->testFunctionEmittingSignalWithOneArgument();
上述代码将产生以下输出
Got to Test_Slot_Class::testSlotForSignalWithNoArguments<br />
Got to Test_Slot_Class::testSlotForSignalWithOneArgument<br />
Test_Model_Class Object
(
)
Got to Test_Slot_Class::testSlotForSignalWithOneArgument<br />
Test_Model_Class Object
(
)