1 | <?php |
||
21 | class Event extends AbstractEvent |
||
22 | { |
||
23 | /** |
||
24 | * Socket linked to this event |
||
25 | * |
||
26 | * @var SocketInterface |
||
27 | */ |
||
28 | private $socket; |
||
29 | |||
30 | /** |
||
31 | * User data for this event |
||
32 | * |
||
33 | * @var mixed |
||
34 | */ |
||
35 | private $context; |
||
36 | |||
37 | /** |
||
38 | * Request executor |
||
39 | * |
||
40 | * @var RequestExecutorInterface |
||
41 | */ |
||
42 | private $executor; |
||
43 | |||
44 | /** |
||
45 | * This event type |
||
46 | * |
||
47 | * @var string |
||
48 | */ |
||
49 | private $type; |
||
50 | |||
51 | /** |
||
52 | * Flag to stop this socket request |
||
53 | * |
||
54 | * @var bool |
||
55 | */ |
||
56 | private $isCancelled; |
||
57 | |||
58 | /** |
||
59 | * Constructor |
||
60 | * |
||
61 | * @param RequestExecutorInterface $executor Request executor object |
||
62 | * @param SocketInterface $socket Socket for this request |
||
63 | * @param mixed $context Any optional user data for event |
||
64 | * @param string $type One of EventType::* constants |
||
65 | */ |
||
66 | 222 | public function __construct(RequestExecutorInterface $executor, SocketInterface $socket, $context, $type) |
|
67 | { |
||
68 | 222 | $this->executor = $executor; |
|
69 | 222 | $this->socket = $socket; |
|
70 | 222 | $this->context = $context; |
|
71 | 222 | $this->type = $type; |
|
72 | 222 | $this->isCancelled = false; |
|
73 | 222 | } |
|
74 | |||
75 | /** |
||
76 | * Return associated socket |
||
77 | * |
||
78 | * @return SocketInterface |
||
79 | */ |
||
80 | 15 | public function getSocket() |
|
81 | { |
||
82 | 15 | return $this->socket; |
|
83 | } |
||
84 | |||
85 | /** |
||
86 | * Return user specified context |
||
87 | * |
||
88 | * @return mixed |
||
89 | */ |
||
90 | 30 | public function getContext() |
|
91 | { |
||
92 | 30 | return $this->context; |
|
93 | } |
||
94 | |||
95 | /** |
||
96 | * Return RequestExecutor |
||
97 | * |
||
98 | * @return RequestExecutorInterface |
||
99 | */ |
||
100 | 24 | public function getExecutor() |
|
101 | { |
||
102 | 24 | return $this->executor; |
|
103 | } |
||
104 | |||
105 | /** |
||
106 | * Return type of this event |
||
107 | * |
||
108 | * @return string One of EventType::* consts |
||
109 | */ |
||
110 | 170 | public function getType() |
|
111 | { |
||
112 | 170 | return $this->type; |
|
113 | } |
||
114 | |||
115 | /** |
||
116 | * Return flag whether this socket operation is cancelled |
||
117 | * |
||
118 | * @return boolean |
||
119 | */ |
||
120 | 142 | public function isOperationCancelled() |
|
121 | { |
||
122 | 142 | return $this->isCancelled; |
|
123 | } |
||
124 | |||
125 | /** |
||
126 | * Sets cancel this operation flag |
||
127 | * |
||
128 | * @param boolean $isCancelled Cancel flag |
||
129 | * |
||
130 | * @return void |
||
131 | */ |
||
132 | 12 | public function cancelThisOperation($isCancelled = true) |
|
136 | } |
||
137 |