-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.php
85 lines (70 loc) · 2.39 KB
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
// Display all errors in this example
error_reporting( E_ALL );
ini_set('display_errors', 1);
// Set include path ( for __autoload )
set_include_path(implode(PATH_SEPARATOR, array(
dirname(realpath(__FILE__)).'/',
get_include_path(),
)));
require "src/RCS/Core/Object.php";
require "src/RCS/Core/Event.php";
// Lets start with a class that extends \RCS\Core\Object
/**
* @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();