@@ -50,7 +50,8 @@ discard block |
||
50 | 50 | /** |
51 | 51 | * Output some data |
52 | 52 | * @param string String to out |
53 | - * @return boolean Success |
|
53 | + * @param string $s |
|
54 | + * @return boolean|null Success |
|
54 | 55 | */ |
55 | 56 | public function out($s, $flush = true) { |
56 | 57 | } |
@@ -222,6 +223,7 @@ discard block |
||
222 | 223 | |
223 | 224 | /** |
224 | 225 | * Adds new callback called before the request finished |
226 | + * @param Closure $callback |
|
225 | 227 | * @return void |
226 | 228 | */ |
227 | 229 | public function registerShutdownFunction($callback) { |
@@ -48,10 +48,10 @@ discard block |
||
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
51 | - * Output some data |
|
52 | - * @param string String to out |
|
53 | - * @return boolean Success |
|
54 | - */ |
|
51 | + * Output some data |
|
52 | + * @param string String to out |
|
53 | + * @return boolean Success |
|
54 | + */ |
|
55 | 55 | public function out($s, $flush = true) { |
56 | 56 | } |
57 | 57 | |
@@ -195,11 +195,11 @@ discard block |
||
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
198 | - * Get integer value from the given variable |
|
199 | - * @param Reference of variable. |
|
200 | - * @param array Optional. Possible values. |
|
201 | - * @return string Value. |
|
202 | - */ |
|
198 | + * Get integer value from the given variable |
|
199 | + * @param Reference of variable. |
|
200 | + * @param array Optional. Possible values. |
|
201 | + * @return string Value. |
|
202 | + */ |
|
203 | 203 | public static function getInteger(&$var, $values = null) { |
204 | 204 | if (is_string($var) && ctype_digit($var)) { |
205 | 205 | $var = (int) $var; |
@@ -412,9 +412,7 @@ |
||
412 | 412 | |
413 | 413 | if (Daemon::$compatMode) { |
414 | 414 | return; |
415 | - } |
|
416 | - |
|
417 | - ++Daemon::$process->counterGC; |
|
415 | + }++Daemon::$process->counterGC; |
|
418 | 416 | |
419 | 417 | if (Daemon::$compatMode) { |
420 | 418 | return; |
@@ -83,8 +83,7 @@ discard block |
||
83 | 83 | $ret = $this->run(); |
84 | 84 | if (($ret === Request::STATE_FINISHED) || ($ret === null)) { |
85 | 85 | $this->finish(); |
86 | - } |
|
87 | - elseif ($ret === Request::STATE_WAITING) { |
|
86 | + } elseif ($ret === Request::STATE_WAITING) { |
|
88 | 87 | $this->state = $ret; |
89 | 88 | } |
90 | 89 | } catch (RequestSleepException $e) { |
@@ -110,8 +109,7 @@ discard block |
||
110 | 109 | handleStatus: |
111 | 110 | if ($this->state === Request::STATE_FINISHED) { |
112 | 111 | $this->free(); |
113 | - } |
|
114 | - elseif ($this->state === REQUEST::STATE_WAITING) { |
|
112 | + } elseif ($this->state === REQUEST::STATE_WAITING) { |
|
115 | 113 | $this->ev->add($this->sleepTime); |
116 | 114 | } |
117 | 115 | } |
@@ -271,8 +269,7 @@ discard block |
||
271 | 269 | |
272 | 270 | if (!$set) { |
273 | 271 | throw new RequestSleepException; |
274 | - } |
|
275 | - else { |
|
272 | + } else { |
|
276 | 273 | $this->ev->del(); |
277 | 274 | $this->ev->add($this->sleepTime); |
278 | 275 | } |
@@ -6,6 +6,9 @@ discard block |
||
6 | 6 | public $name; |
7 | 7 | public $key; |
8 | 8 | |
9 | + /** |
|
10 | + * @param string $name |
|
11 | + */ |
|
9 | 12 | public function __construct($path, $segsize, $name, $create = false) { |
10 | 13 | $this->path = $path; |
11 | 14 | $this->segsize = $segsize; |
@@ -55,6 +58,9 @@ discard block |
||
55 | 58 | } while ($r); |
56 | 59 | } |
57 | 60 | |
61 | + /** |
|
62 | + * @param string $data |
|
63 | + */ |
|
58 | 64 | public function write($data, $offset) { |
59 | 65 | $segno = floor($offset / $this->segsize); |
60 | 66 | if (!isset($this->segments[$segno])) { |
@@ -10,17 +10,17 @@ |
||
10 | 10 | $this->path = $path; |
11 | 11 | $this->segsize = $segsize; |
12 | 12 | $this->name = $name; |
13 | - if ($create && !touch($this->path)) { |
|
13 | + if ($create && !touch($this->path)) { |
|
14 | 14 | Daemon::log('Couldn\'t touch IPC file \'' . $this->path . '\'.'); |
15 | 15 | exit(0); |
16 | 16 | } |
17 | 17 | |
18 | - if (($this->key = ftok($this->path,'t')) === false) { |
|
18 | + if (($this->key = ftok($this->path, 't')) === false) { |
|
19 | 19 | Daemon::log('Couldn\'t ftok() IPC file \'' . $this->path . '\'.'); |
20 | 20 | exit(0); |
21 | 21 | } |
22 | 22 | if (!$this->open(0, $create) && $create) { |
23 | - Daemon::log('Couldn\'t open IPC-'.$this->name.' shared memory segment (key=' . $this->key . ', segsize=' . $this->segsize . ', uid=' . posix_getuid() . ', path = '.$this->path.').'); |
|
23 | + Daemon::log('Couldn\'t open IPC-' . $this->name . ' shared memory segment (key=' . $this->key . ', segsize=' . $this->segsize . ', uid=' . posix_getuid() . ', path = ' . $this->path . ').'); |
|
24 | 24 | exit(0); |
25 | 25 | } |
26 | 26 | } |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | |
154 | 154 | /** |
155 | 155 | * Starts the process |
156 | - * @return void |
|
156 | + * @return null|integer |
|
157 | 157 | */ |
158 | 158 | public function start($clearstack = true) { |
159 | 159 | $pid = pcntl_fork(); |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | /** |
206 | 206 | * Sends the signal to parent process |
207 | 207 | * @param integer Signal's number |
208 | - * @return void |
|
208 | + * @return boolean |
|
209 | 209 | */ |
210 | 210 | private function backsig($sig) { |
211 | 211 | return posix_kill(posix_getppid(), $sig); |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | /** |
215 | 215 | * Delays the process execution for the given number of seconds |
216 | 216 | * @param integer Sleep time in seconds |
217 | - * @return void |
|
217 | + * @return boolean |
|
218 | 218 | */ |
219 | 219 | public function sleep($s) { |
220 | 220 | static $interval = 0.2; |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | /** |
275 | 275 | * Terminates the process |
276 | 276 | * @param boolean Kill? |
277 | - * @return void |
|
277 | + * @return boolean |
|
278 | 278 | */ |
279 | 279 | public function stop($kill = false) { |
280 | 280 | $this->shutdown = true; |
@@ -328,6 +328,7 @@ discard block |
||
328 | 328 | |
329 | 329 | /** |
330 | 330 | * Waits until children is alive |
331 | + * @param boolean $check |
|
331 | 332 | * @return void |
332 | 333 | */ |
333 | 334 | protected function waitAll($check) { |
@@ -346,6 +347,7 @@ discard block |
||
346 | 347 | /** |
347 | 348 | * Sets a title of the current process |
348 | 349 | * @param string Title |
350 | + * @param string $title |
|
349 | 351 | * @return void |
350 | 352 | */ |
351 | 353 | protected function setproctitle($title) { |
@@ -360,7 +362,7 @@ discard block |
||
360 | 362 | * Waits for signals, with a timeout |
361 | 363 | * @param int Seconds |
362 | 364 | * @param int Nanoseconds |
363 | - * @return void |
|
365 | + * @return boolean |
|
364 | 366 | */ |
365 | 367 | protected function sigwait($sec = 0, $nano = 0.3e9) { |
366 | 368 | $siginfo = NULL; |
@@ -382,6 +384,11 @@ discard block |
||
382 | 384 | |
383 | 385 | if (!function_exists('pcntl_sigtimedwait')) { |
384 | 386 | // @todo $signals or Thread::$signals? |
387 | + |
|
388 | + /** |
|
389 | + * @param integer $sec |
|
390 | + * @param double $nano |
|
391 | + */ |
|
385 | 392 | function pcntl_sigtimedwait($signals, $siginfo, $sec, $nano) { |
386 | 393 | pcntl_signal_dispatch(); |
387 | 394 |
@@ -92,9 +92,9 @@ |
||
92 | 92 | ) { |
93 | 93 | continue; |
94 | 94 | } |
95 | - $ev = Event::signal($this->eventBase, $no, array($this,'eventSighandler'), array($no)); |
|
95 | + $ev = Event::signal($this->eventBase, $no, array($this, 'eventSighandler'), array($no)); |
|
96 | 96 | if (!$ev) { |
97 | - $this->log('Cannot event_set for '.$name.' signal'); |
|
97 | + $this->log('Cannot event_set for ' . $name . ' signal'); |
|
98 | 98 | } |
99 | 99 | $ev->add(); |
100 | 100 | $this->sigEvents[$no] = $ev; |
@@ -160,8 +160,7 @@ discard block |
||
160 | 160 | |
161 | 161 | if ($pid === -1) { |
162 | 162 | throw new Exception('Could not fork'); |
163 | - } |
|
164 | - elseif ($pid === 0) { // we are the child |
|
163 | + } elseif ($pid === 0) { // we are the child |
|
165 | 164 | $thread = $this; |
166 | 165 | $thread->pid = posix_getpid(); |
167 | 166 | if (!$thread->delayedSigReg) { |
@@ -187,8 +186,7 @@ discard block |
||
187 | 186 | protected function sighandler($signo) { |
188 | 187 | if (is_callable($c = array($this, strtolower(self::$signals[$signo])))) { |
189 | 188 | call_user_func($c); |
190 | - } |
|
191 | - elseif (is_callable($c = array($this, 'sigunknown'))) { |
|
189 | + } elseif (is_callable($c = array($this, 'sigunknown'))) { |
|
192 | 190 | call_user_func($c, $signo); |
193 | 191 | } |
194 | 192 | } |
@@ -48,6 +48,10 @@ |
||
48 | 48 | $obj = new self($cb, $timeout, $id, $priority); |
49 | 49 | return $obj->id; |
50 | 50 | } |
51 | + |
|
52 | + /** |
|
53 | + * @param integer $timeout |
|
54 | + */ |
|
51 | 55 | public static function setTimeout($id, $timeout = NULL) { |
52 | 56 | if (isset(Timer::$list[$id])) { |
53 | 57 | Timer::$list[$id]->timeout($timeout); |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | Timer::$list[$id]->cancel(); |
66 | 66 | } |
67 | 67 | } |
68 | - public function timeout($timeout = null) { |
|
68 | + public function timeout($timeout = null) { |
|
69 | 69 | if ($timeout !== null) { |
70 | 70 | $this->lastTimeout = $timeout; |
71 | 71 | } |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | public function cancel() { |
75 | 75 | $this->ev->del(); |
76 | 76 | } |
77 | - public function finish(){ |
|
77 | + public function finish() { |
|
78 | 78 | $this->free(); |
79 | 79 | } |
80 | 80 | public function __destruct() { |
@@ -19,6 +19,9 @@ discard block |
||
19 | 19 | |
20 | 20 | public static $zombie = 0; |
21 | 21 | |
22 | + /** |
|
23 | + * @param string $name |
|
24 | + */ |
|
22 | 25 | public function request($addr, $name, $data, $cb) { |
23 | 26 | $e = explode(':', $addr); |
24 | 27 | $this->getConnection('valve://[udp:' . $e[0] . ']' . (isset($e[1]) ? ':'.$e[1] : '') . '/', function($conn) use ($cb, $addr, $data, $name) { |
@@ -90,6 +93,9 @@ discard block |
||
90 | 93 | $this->request('info', null, $cb); |
91 | 94 | } |
92 | 95 | |
96 | + /** |
|
97 | + * @param string $name |
|
98 | + */ |
|
93 | 99 | public function request($name, $data = null, $cb = null) { |
94 | 100 | $packet = "\xFF\xFF\xFF\xFF"; |
95 | 101 | if ($name === 'ping') { |
@@ -198,11 +198,11 @@ discard block |
||
198 | 198 | $info['secure'] = Binary::getByte($st); |
199 | 199 | } |
200 | 200 | elseif ($type === ValveClient::S2A_INFO_SOURCE) { |
201 | - $info['srvaddress'] = Binary::getString($st); |
|
202 | - $info['hostname'] = Binary::getString($st); |
|
203 | - $info['map'] = Binary::getString($st); |
|
204 | - $info['gamedir'] = Binary::getString($st); |
|
205 | - $info['gamedescr'] = Binary::getString($st); |
|
201 | + $info['srvaddress'] = Binary::getString($st); |
|
202 | + $info['hostname'] = Binary::getString($st); |
|
203 | + $info['map'] = Binary::getString($st); |
|
204 | + $info['gamedir'] = Binary::getString($st); |
|
205 | + $info['gamedescr'] = Binary::getString($st); |
|
206 | 206 | $info['playersnum'] = Binary::getByte($st); |
207 | 207 | $info['playersmax'] = Binary::getByte($st); |
208 | 208 | $info['proto'] = Binary::getByte($st); |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | $info['mod_size'] = Binary::getDWord($st); |
219 | 219 | $info['mod_serverside'] = Binary::getByte($st); |
220 | 220 | $info['mod_customdll'] = Binary::getByte($st); |
221 | - } |
|
221 | + } |
|
222 | 222 | $info['secure'] = Binary::getByte($st); |
223 | 223 | $info['botsnum'] = Binary::getByte($st); |
224 | 224 | } |
@@ -19,9 +19,9 @@ discard block |
||
19 | 19 | |
20 | 20 | public static $zombie = 0; |
21 | 21 | |
22 | - public function request($addr, $name, $data, $cb) { |
|
22 | + public function request($addr, $name, $data, $cb) { |
|
23 | 23 | $e = explode(':', $addr); |
24 | - $this->getConnection('valve://[udp:' . $e[0] . ']' . (isset($e[1]) ? ':'.$e[1] : '') . '/', function($conn) use ($cb, $addr, $data, $name) { |
|
24 | + $this->getConnection('valve://[udp:' . $e[0] . ']' . (isset($e[1]) ? ':' . $e[1] : '') . '/', function($conn) use ($cb, $addr, $data, $name) { |
|
25 | 25 | if (!$conn->connected) { |
26 | 26 | call_user_func($cb, $conn, false); |
27 | 27 | return; |
@@ -33,13 +33,13 @@ discard block |
||
33 | 33 | |
34 | 34 | public function ping($addr, $cb) { |
35 | 35 | $e = explode(':', $addr); |
36 | - $this->getConnection('valve://[udp:' . $e[0] . ']' . (isset($e[1]) ? ':'.$e[1] : '') . '/ping', function($conn) use ($cb) { |
|
36 | + $this->getConnection('valve://[udp:' . $e[0] . ']' . (isset($e[1]) ? ':' . $e[1] : '') . '/ping', function($conn) use ($cb) { |
|
37 | 37 | if (!$conn->connected) { |
38 | 38 | call_user_func($cb, $conn, false); |
39 | 39 | return; |
40 | 40 | } |
41 | 41 | $mt = microtime(true); |
42 | - $conn->request('ping', null, function ($conn, $success) use ($mt, $cb) { |
|
42 | + $conn->request('ping', null, function($conn, $success) use ($mt, $cb) { |
|
43 | 43 | call_user_func($cb, $conn, $success ? (microtime(true) - $mt) : false); |
44 | 44 | }); |
45 | 45 | }); |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | } |
51 | 51 | |
52 | 52 | public function requestPlayers($addr, $cb) { |
53 | - $this->request($addr, 'challenge', null, function ($conn, $result) use ($cb) { |
|
53 | + $this->request($addr, 'challenge', null, function($conn, $result) use ($cb) { |
|
54 | 54 | if (is_array($result)) { |
55 | 55 | $cb($conn, $result); |
56 | 56 | return; |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | public $timeout = 1; |
78 | 78 | |
79 | 79 | public function requestPlayers($cb) { |
80 | - $this->request('challenge', null, function ($conn, $result) use ($cb) { |
|
80 | + $this->request('challenge', null, function($conn, $result) use ($cb) { |
|
81 | 81 | if (is_array($result)) { |
82 | 82 | call_user_func($cb, $conn, $result); |
83 | 83 | return; |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | for ($i = 1; $i < $playersn; ++$i) { |
160 | 160 | $n = Binary::getByte($st); |
161 | 161 | $name = Binary::getString($st); |
162 | - $score = Binary::getDWord($st,TRUE); |
|
162 | + $score = Binary::getDWord($st, TRUE); |
|
163 | 163 | if (strlen($st) === 0) { |
164 | 164 | break; |
165 | 165 | } |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | $info['mod_website'] = Binary::getString($st); |
215 | 215 | $info['mod_downloadserver'] = Binary::getString($st); |
216 | 216 | $info['mod_unused'] = Binary::getString($st); |
217 | - $info['mod_version'] = Binary::getDWord($st,TRUE); |
|
217 | + $info['mod_version'] = Binary::getDWord($st, TRUE); |
|
218 | 218 | $info['mod_size'] = Binary::getDWord($st); |
219 | 219 | $info['mod_serverside'] = Binary::getByte($st); |
220 | 220 | $info['mod_customdll'] = Binary::getByte($st); |
@@ -134,18 +134,14 @@ discard block |
||
134 | 134 | $type = Binary::getChar($this->buf); |
135 | 135 | if (($type === ValveClient::S2A_INFO) || ($type === ValveClient::S2A_INFO_SOURCE)) { |
136 | 136 | $result = $this->parseInfo($this->buf, $type); |
137 | - } |
|
138 | - elseif ($type === ValveClient::S2A_PLAYER) { |
|
137 | + } elseif ($type === ValveClient::S2A_PLAYER) { |
|
139 | 138 | $result = $this->parsePlayers($this->buf); |
140 | - } |
|
141 | - elseif ($type === ValveClient::S2A_SERVERQUERY_GETCHALLENGE) { |
|
139 | + } elseif ($type === ValveClient::S2A_SERVERQUERY_GETCHALLENGE) { |
|
142 | 140 | $result = binarySubstr($this->buf, 0, 4); |
143 | 141 | $this->buf = binarySubstr($this->buf, 5); |
144 | - } |
|
145 | - elseif ($type === ValveClient::S2A_PONG) { |
|
142 | + } elseif ($type === ValveClient::S2A_PONG) { |
|
146 | 143 | $result = true; |
147 | - } |
|
148 | - else { |
|
144 | + } else { |
|
149 | 145 | $result = null; |
150 | 146 | } |
151 | 147 | $this->onResponse->executeOne($this, $result); |
@@ -196,8 +192,7 @@ discard block |
||
196 | 192 | $info['serveros'] = Binary::getChar($st); |
197 | 193 | $info['passworded'] = Binary::getByte($st); |
198 | 194 | $info['secure'] = Binary::getByte($st); |
199 | - } |
|
200 | - elseif ($type === ValveClient::S2A_INFO_SOURCE) { |
|
195 | + } elseif ($type === ValveClient::S2A_INFO_SOURCE) { |
|
201 | 196 | $info['srvaddress'] = Binary::getString($st); |
202 | 197 | $info['hostname'] = Binary::getString($st); |
203 | 198 | $info['map'] = Binary::getString($st); |
@@ -12,10 +12,16 @@ discard block |
||
12 | 12 | const STRING = NULL; |
13 | 13 | const BINARY = NULL; |
14 | 14 | |
15 | + /** |
|
16 | + * @param WebSocketServerConnection $connection |
|
17 | + */ |
|
15 | 18 | public function __construct($connection) { |
16 | 19 | $this->connection = $connection; |
17 | 20 | } |
18 | 21 | |
22 | + /** |
|
23 | + * @return integer |
|
24 | + */ |
|
19 | 25 | public function getFrameType($type) { |
20 | 26 | if (is_int($type)) { |
21 | 27 | return $type; |
@@ -45,7 +51,7 @@ discard block |
||
45 | 51 | /** |
46 | 52 | * Returns handshaked data for reply |
47 | 53 | * @param string Received data (no use in this class) |
48 | - * @return string Handshaked data |
|
54 | + * @return boolean Handshaked data |
|
49 | 55 | */ |
50 | 56 | |
51 | 57 | public function getHandshakeReply($data) { |
@@ -23,11 +23,11 @@ discard block |
||
23 | 23 | if ($type === null) { |
24 | 24 | $type = 'STRING'; |
25 | 25 | } |
26 | - $frametype = @constant($a = get_class($this) .'::' . $type) ; |
|
27 | - if ($frametype === null) { |
|
28 | - Daemon::log(__METHOD__ . ' : Undefined frametype "' . $type . '"') ; |
|
29 | - } |
|
30 | - return $frametype ; |
|
26 | + $frametype = @constant($a = get_class($this) .'::' . $type) ; |
|
27 | + if ($frametype === null) { |
|
28 | + Daemon::log(__METHOD__ . ' : Undefined frametype "' . $type . '"') ; |
|
29 | + } |
|
30 | + return $frametype ; |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | public function onHandshake() { |
@@ -42,14 +42,14 @@ discard block |
||
42 | 42 | $this->connection->buf = "" ; |
43 | 43 | } |
44 | 44 | |
45 | - /** |
|
46 | - * Returns handshaked data for reply |
|
45 | + /** |
|
46 | + * Returns handshaked data for reply |
|
47 | 47 | * @param string Received data (no use in this class) |
48 | - * @return string Handshaked data |
|
49 | - */ |
|
48 | + * @return string Handshaked data |
|
49 | + */ |
|
50 | 50 | |
51 | - public function getHandshakeReply($data) { |
|
51 | + public function getHandshakeReply($data) { |
|
52 | 52 | return false; |
53 | - } |
|
53 | + } |
|
54 | 54 | |
55 | 55 | } |
56 | 56 | \ No newline at end of file |
@@ -23,11 +23,11 @@ discard block |
||
23 | 23 | if ($type === null) { |
24 | 24 | $type = 'STRING'; |
25 | 25 | } |
26 | - $frametype = @constant($a = get_class($this) .'::' . $type) ; |
|
26 | + $frametype = @constant($a = get_class($this) . '::' . $type); |
|
27 | 27 | if ($frametype === null) { |
28 | - Daemon::log(__METHOD__ . ' : Undefined frametype "' . $type . '"') ; |
|
28 | + Daemon::log(__METHOD__ . ' : Undefined frametype "' . $type . '"'); |
|
29 | 29 | } |
30 | - return $frametype ; |
|
30 | + return $frametype; |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | public function onHandshake() { |
@@ -35,11 +35,11 @@ discard block |
||
35 | 35 | } |
36 | 36 | |
37 | 37 | public function sendFrame($data, $type) { |
38 | - $this->connection->write($this->encodeFrame($data, $type)) ; |
|
38 | + $this->connection->write($this->encodeFrame($data, $type)); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | public function onRead() { |
42 | - $this->connection->buf = "" ; |
|
42 | + $this->connection->buf = ""; |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
@@ -16,6 +16,9 @@ discard block |
||
16 | 16 | public $opcodes; |
17 | 17 | public $outgoingCompression = 0; |
18 | 18 | |
19 | + /** |
|
20 | + * @param WebSocketServerConnection $connection |
|
21 | + */ |
|
19 | 22 | public function __construct($connection) { |
20 | 23 | $this->connection = $connection; |
21 | 24 | $this->opcodes = array( |
@@ -95,6 +98,9 @@ discard block |
||
95 | 98 | return $this->encodeFragment($data, $type, $fin, $rsv1, $rsv2, $rsv3); |
96 | 99 | } |
97 | 100 | |
101 | + /** |
|
102 | + * @param string $type |
|
103 | + */ |
|
98 | 104 | protected function encodeFragment($data, $type, $fin = 1, $rsv1 = 0, $rsv2 = 0, $rsv3 = 0) { |
99 | 105 | $mask = chr(rand(0, 0xFF)) . |
100 | 106 | chr(rand(0, 0xFF)) . |
@@ -132,6 +138,12 @@ discard block |
||
132 | 138 | } |
133 | 139 | return $packet; |
134 | 140 | } |
141 | + |
|
142 | + /** |
|
143 | + * @param string $mask |
|
144 | + * |
|
145 | + * @return string |
|
146 | + */ |
|
135 | 147 | public function mask ($data, $mask) { |
136 | 148 | for ($i = 0, $l = strlen($data), $ml = strlen($mask); $i < $l; $i++) { |
137 | 149 | $data[$i] = $data[$i] ^ $mask[$i % $ml] ; |
@@ -142,6 +154,7 @@ discard block |
||
142 | 154 | * Converts binary string to integer |
143 | 155 | * @param string Binary string |
144 | 156 | * @param boolean Optional. Little endian. Default value - false. |
157 | + * @param string $str |
|
145 | 158 | * @return integer Resulting integer |
146 | 159 | */ |
147 | 160 | public function bytes2int($str, $l = FALSE) |
@@ -29,53 +29,53 @@ discard block |
||
29 | 29 | } |
30 | 30 | |
31 | 31 | public function onHandshake(){ |
32 | - if (!isset($this->connection->server['HTTP_SEC_WEBSOCKET_KEY']) || !isset($this->connection->server['HTTP_SEC_WEBSOCKET_VERSION'])) { |
|
32 | + if (!isset($this->connection->server['HTTP_SEC_WEBSOCKET_KEY']) || !isset($this->connection->server['HTTP_SEC_WEBSOCKET_VERSION'])) { |
|
33 | 33 | return false; |
34 | 34 | } |
35 | 35 | if ($this->connection->server['HTTP_SEC_WEBSOCKET_VERSION'] != '13' && $this->connection->server['HTTP_SEC_WEBSOCKET_VERSION'] != '8') { |
36 | - return false; |
|
37 | - } |
|
36 | + return false; |
|
37 | + } |
|
38 | 38 | |
39 | 39 | return true; |
40 | 40 | } |
41 | 41 | |
42 | - /** |
|
43 | - * Returns handshaked data for reply |
|
42 | + /** |
|
43 | + * Returns handshaked data for reply |
|
44 | 44 | * @param string Received data (no use in this class) |
45 | - * @return string Handshaked data |
|
46 | - */ |
|
45 | + * @return string Handshaked data |
|
46 | + */ |
|
47 | 47 | |
48 | - public function getHandshakeReply($data) { |
|
49 | - if ($this->onHandshake()) { |
|
50 | - if (isset($this->connection->server['HTTP_ORIGIN'])) { |
|
48 | + public function getHandshakeReply($data) { |
|
49 | + if ($this->onHandshake()) { |
|
50 | + if (isset($this->connection->server['HTTP_ORIGIN'])) { |
|
51 | 51 | $this->connection->server['HTTP_SEC_WEBSOCKET_ORIGIN'] = $this->connection->server['HTTP_ORIGIN']; |
52 | 52 | } |
53 | - if (!isset($this->connection->server['HTTP_SEC_WEBSOCKET_ORIGIN'])) |
|
53 | + if (!isset($this->connection->server['HTTP_SEC_WEBSOCKET_ORIGIN'])) |
|
54 | 54 | { |
55 | - $this->connection->server['HTTP_SEC_WEBSOCKET_ORIGIN'] = '' ; |
|
56 | - } |
|
57 | - $reply = "HTTP/1.1 101 Switching Protocols\r\n" |
|
58 | - . "Upgrade: WebSocket\r\n" |
|
59 | - . "connection: Upgrade\r\n" |
|
60 | - . "Date: ".date('r')."\r\n" |
|
61 | - . "Sec-WebSocket-Origin: " . $this->connection->server['HTTP_SEC_WEBSOCKET_ORIGIN'] . "\r\n" |
|
62 | - . "Sec-WebSocket-Location: ws://" . $this->connection->server['HTTP_HOST'] . $this->connection->server['REQUEST_URI'] . "\r\n" |
|
63 | - . "Sec-WebSocket-Accept: " . base64_encode(sha1(trim($this->connection->server['HTTP_SEC_WEBSOCKET_KEY']) . "258EAFA5-E914-47DA-95CA-C5AB0DC85B11", true)) . "\r\n"; |
|
55 | + $this->connection->server['HTTP_SEC_WEBSOCKET_ORIGIN'] = '' ; |
|
56 | + } |
|
57 | + $reply = "HTTP/1.1 101 Switching Protocols\r\n" |
|
58 | + . "Upgrade: WebSocket\r\n" |
|
59 | + . "connection: Upgrade\r\n" |
|
60 | + . "Date: ".date('r')."\r\n" |
|
61 | + . "Sec-WebSocket-Origin: " . $this->connection->server['HTTP_SEC_WEBSOCKET_ORIGIN'] . "\r\n" |
|
62 | + . "Sec-WebSocket-Location: ws://" . $this->connection->server['HTTP_HOST'] . $this->connection->server['REQUEST_URI'] . "\r\n" |
|
63 | + . "Sec-WebSocket-Accept: " . base64_encode(sha1(trim($this->connection->server['HTTP_SEC_WEBSOCKET_KEY']) . "258EAFA5-E914-47DA-95CA-C5AB0DC85B11", true)) . "\r\n"; |
|
64 | 64 | |
65 | - if (isset($this->connection->server['HTTP_SEC_WEBSOCKET_PROTOCOL'])) { |
|
66 | - $reply .= "Sec-WebSocket-Protocol: " . $this->connection->server['HTTP_SEC_WEBSOCKET_PROTOCOL'] . "\r\n"; |
|
67 | - } |
|
65 | + if (isset($this->connection->server['HTTP_SEC_WEBSOCKET_PROTOCOL'])) { |
|
66 | + $reply .= "Sec-WebSocket-Protocol: " . $this->connection->server['HTTP_SEC_WEBSOCKET_PROTOCOL'] . "\r\n"; |
|
67 | + } |
|
68 | 68 | |
69 | 69 | if ($this->connection->pool->config->expose->value) { |
70 | 70 | $reply .= 'X-Powered-By: phpDaemon/' . Daemon::$version . "\r\n"; |
71 | 71 | } |
72 | 72 | |
73 | - $reply .= "\r\n"; |
|
74 | - return $reply ; |
|
75 | - } |
|
73 | + $reply .= "\r\n"; |
|
74 | + return $reply ; |
|
75 | + } |
|
76 | 76 | |
77 | 77 | return false; |
78 | - } |
|
78 | + } |
|
79 | 79 | |
80 | 80 | /** |
81 | 81 | * Data encoding, according to related IETF draft |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | * @see http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-10#page-16 |
84 | 84 | */ |
85 | 85 | |
86 | - protected function encodeFrame($data, $type = 'STRING') { |
|
86 | + protected function encodeFrame($data, $type = 'STRING') { |
|
87 | 87 | $fin = 1; |
88 | 88 | $rsv1 = 0; |
89 | 89 | $rsv2 = 0; |
@@ -93,40 +93,40 @@ discard block |
||
93 | 93 | $rsv1 = 1; |
94 | 94 | } |
95 | 95 | return $this->encodeFragment($data, $type, $fin, $rsv1, $rsv2, $rsv3); |
96 | - } |
|
96 | + } |
|
97 | 97 | |
98 | 98 | protected function encodeFragment($data, $type, $fin = 1, $rsv1 = 0, $rsv2 = 0, $rsv3 = 0) { |
99 | - $mask = chr(rand(0, 0xFF)) . |
|
99 | + $mask = chr(rand(0, 0xFF)) . |
|
100 | 100 | chr(rand(0, 0xFF)) . |
101 | 101 | chr(rand(0, 0xFF)) . |
102 | 102 | chr(rand(0, 0xFF)) ; |
103 | 103 | $packet = chr(bindec($fin . $rsv1 . $rsv2 . $rsv3 . str_pad(decbin($this->getFrameType($type)), 4, '0', STR_PAD_LEFT))); |
104 | - $dataLength = strlen($data); |
|
104 | + $dataLength = strlen($data); |
|
105 | 105 | $isMasked = false; |
106 | 106 | $isMaskedInt = $isMasked ? 128 : 0; |
107 | - if ($dataLength <= 125) |
|
108 | - { |
|
109 | - $packet .= chr($dataLength + $isMaskedInt); |
|
110 | - } |
|
111 | - elseif ($dataLength <= 65535) |
|
112 | - { |
|
113 | - $packet .= chr(126 + $isMaskedInt) . // 126 + 128 |
|
114 | - chr($dataLength >> 8) . |
|
115 | - chr($dataLength & 0xFF); |
|
116 | - } |
|
117 | - else { |
|
118 | - $packet .= chr(127 + $isMaskedInt) . // 127 + 128 |
|
119 | - chr($dataLength >> 56) . |
|
120 | - chr($dataLength >> 48) . |
|
121 | - chr($dataLength >> 40) . |
|
122 | - chr($dataLength >> 32) . |
|
123 | - chr($dataLength >> 24) . |
|
124 | - chr($dataLength >> 16) . |
|
125 | - chr($dataLength >> 8) . |
|
126 | - chr($dataLength & 0xFF); |
|
127 | - } |
|
128 | - if ($isMasked) { |
|
129 | - $packet .= $mask . $this->mask($data, $mask); |
|
107 | + if ($dataLength <= 125) |
|
108 | + { |
|
109 | + $packet .= chr($dataLength + $isMaskedInt); |
|
110 | + } |
|
111 | + elseif ($dataLength <= 65535) |
|
112 | + { |
|
113 | + $packet .= chr(126 + $isMaskedInt) . // 126 + 128 |
|
114 | + chr($dataLength >> 8) . |
|
115 | + chr($dataLength & 0xFF); |
|
116 | + } |
|
117 | + else { |
|
118 | + $packet .= chr(127 + $isMaskedInt) . // 127 + 128 |
|
119 | + chr($dataLength >> 56) . |
|
120 | + chr($dataLength >> 48) . |
|
121 | + chr($dataLength >> 40) . |
|
122 | + chr($dataLength >> 32) . |
|
123 | + chr($dataLength >> 24) . |
|
124 | + chr($dataLength >> 16) . |
|
125 | + chr($dataLength >> 8) . |
|
126 | + chr($dataLength & 0xFF); |
|
127 | + } |
|
128 | + if ($isMasked) { |
|
129 | + $packet .= $mask . $this->mask($data, $mask); |
|
130 | 130 | } else { |
131 | 131 | $packet .= $data; |
132 | 132 | } |
@@ -134,8 +134,8 @@ discard block |
||
134 | 134 | } |
135 | 135 | public function mask ($data, $mask) { |
136 | 136 | for ($i = 0, $l = strlen($data), $ml = strlen($mask); $i < $l; $i++) { |
137 | - $data[$i] = $data[$i] ^ $mask[$i % $ml] ; |
|
138 | - } |
|
137 | + $data[$i] = $data[$i] ^ $mask[$i % $ml] ; |
|
138 | + } |
|
139 | 139 | return $data; |
140 | 140 | } |
141 | 141 | /** |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | * @see http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-10#page-16 |
194 | 194 | */ |
195 | 195 | |
196 | - public function onRead() { |
|
196 | + public function onRead() { |
|
197 | 197 | $data = ''; |
198 | 198 | while ($this->connection && (($buflen = strlen($this->connection->buf)) >= 1)) { |
199 | 199 | $p = 0; // offset |
@@ -204,15 +204,15 @@ discard block |
||
204 | 204 | $rsv3 = (bool) $firstBits[3]; |
205 | 205 | $opcode = (int) bindec(substr($firstBits, 4, 4)); |
206 | 206 | if ($opcode === 0x8) { // CLOSE |
207 | - $this->connection->finish(); |
|
208 | - return; |
|
207 | + $this->connection->finish(); |
|
208 | + return; |
|
209 | 209 | } |
210 | 210 | $opcodeName = $this->opcodes[$opcode]; |
211 | 211 | $second = ord(binarySubstr($this->connection->buf, $p++, 1)); // second byte integer (masked, payload length) |
212 | 212 | $fin = (bool) ($first >> 7); |
213 | - $isMasked = (bool) ($second >> 7); |
|
214 | - $dataLength = $second & 0x7f; |
|
215 | - if ($dataLength === 0x7e) { // 2 bytes-length |
|
213 | + $isMasked = (bool) ($second >> 7); |
|
214 | + $dataLength = $second & 0x7f; |
|
215 | + if ($dataLength === 0x7e) { // 2 bytes-length |
|
216 | 216 | if ($buflen < $p + 2) { |
217 | 217 | return; // not enough data yet |
218 | 218 | } |
@@ -223,9 +223,9 @@ discard block |
||
223 | 223 | if ($buflen < $p + 4) { |
224 | 224 | return; // not enough data yet |
225 | 225 | } |
226 | - $dataLength = $this->bytes2int(binarySubstr($this->connection->buf, $p, 4)); |
|
227 | - $p += 4; |
|
228 | - } |
|
226 | + $dataLength = $this->bytes2int(binarySubstr($this->connection->buf, $p, 4)); |
|
227 | + $p += 4; |
|
228 | + } |
|
229 | 229 | if ($this->connection->pool->maxAllowedPacket <= $dataLength) { |
230 | 230 | // Too big packet |
231 | 231 | $this->connection->finish(); |
@@ -262,5 +262,5 @@ discard block |
||
262 | 262 | } |
263 | 263 | } |
264 | 264 | } |
265 | - } |
|
265 | + } |
|
266 | 266 | } |
267 | 267 | \ No newline at end of file |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | const BINARY = 0x2; |
13 | 13 | const CONNCLOSE = 0x8; |
14 | 14 | const PING = 0x9; |
15 | - const PONG = 0xA ; |
|
15 | + const PONG = 0xA; |
|
16 | 16 | public $opcodes; |
17 | 17 | public $outgoingCompression = 0; |
18 | 18 | |
@@ -28,8 +28,8 @@ discard block |
||
28 | 28 | ); |
29 | 29 | } |
30 | 30 | |
31 | - public function onHandshake(){ |
|
32 | - if (!isset($this->connection->server['HTTP_SEC_WEBSOCKET_KEY']) || !isset($this->connection->server['HTTP_SEC_WEBSOCKET_VERSION'])) { |
|
31 | + public function onHandshake() { |
|
32 | + if (!isset($this->connection->server['HTTP_SEC_WEBSOCKET_KEY']) || !isset($this->connection->server['HTTP_SEC_WEBSOCKET_VERSION'])) { |
|
33 | 33 | return false; |
34 | 34 | } |
35 | 35 | if ($this->connection->server['HTTP_SEC_WEBSOCKET_VERSION'] != '13' && $this->connection->server['HTTP_SEC_WEBSOCKET_VERSION'] != '8') { |
@@ -52,12 +52,12 @@ discard block |
||
52 | 52 | } |
53 | 53 | if (!isset($this->connection->server['HTTP_SEC_WEBSOCKET_ORIGIN'])) |
54 | 54 | { |
55 | - $this->connection->server['HTTP_SEC_WEBSOCKET_ORIGIN'] = '' ; |
|
55 | + $this->connection->server['HTTP_SEC_WEBSOCKET_ORIGIN'] = ''; |
|
56 | 56 | } |
57 | 57 | $reply = "HTTP/1.1 101 Switching Protocols\r\n" |
58 | 58 | . "Upgrade: WebSocket\r\n" |
59 | 59 | . "connection: Upgrade\r\n" |
60 | - . "Date: ".date('r')."\r\n" |
|
60 | + . "Date: " . date('r') . "\r\n" |
|
61 | 61 | . "Sec-WebSocket-Origin: " . $this->connection->server['HTTP_SEC_WEBSOCKET_ORIGIN'] . "\r\n" |
62 | 62 | . "Sec-WebSocket-Location: ws://" . $this->connection->server['HTTP_HOST'] . $this->connection->server['REQUEST_URI'] . "\r\n" |
63 | 63 | . "Sec-WebSocket-Accept: " . base64_encode(sha1(trim($this->connection->server['HTTP_SEC_WEBSOCKET_KEY']) . "258EAFA5-E914-47DA-95CA-C5AB0DC85B11", true)) . "\r\n"; |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | } |
72 | 72 | |
73 | 73 | $reply .= "\r\n"; |
74 | - return $reply ; |
|
74 | + return $reply; |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | return false; |
@@ -96,10 +96,10 @@ discard block |
||
96 | 96 | } |
97 | 97 | |
98 | 98 | protected function encodeFragment($data, $type, $fin = 1, $rsv1 = 0, $rsv2 = 0, $rsv3 = 0) { |
99 | - $mask = chr(rand(0, 0xFF)) . |
|
99 | + $mask = chr(rand(0, 0xFF)) . |
|
100 | 100 | chr(rand(0, 0xFF)) . |
101 | 101 | chr(rand(0, 0xFF)) . |
102 | - chr(rand(0, 0xFF)) ; |
|
102 | + chr(rand(0, 0xFF)); |
|
103 | 103 | $packet = chr(bindec($fin . $rsv1 . $rsv2 . $rsv3 . str_pad(decbin($this->getFrameType($type)), 4, '0', STR_PAD_LEFT))); |
104 | 104 | $dataLength = strlen($data); |
105 | 105 | $isMasked = false; |
@@ -110,31 +110,31 @@ discard block |
||
110 | 110 | } |
111 | 111 | elseif ($dataLength <= 65535) |
112 | 112 | { |
113 | - $packet .= chr(126 + $isMaskedInt) . // 126 + 128 |
|
113 | + $packet .= chr(126 + $isMaskedInt) . // 126 + 128 |
|
114 | 114 | chr($dataLength >> 8) . |
115 | 115 | chr($dataLength & 0xFF); |
116 | 116 | } |
117 | 117 | else { |
118 | - $packet .= chr(127 + $isMaskedInt) . // 127 + 128 |
|
118 | + $packet .= chr(127 + $isMaskedInt) . // 127 + 128 |
|
119 | 119 | chr($dataLength >> 56) . |
120 | 120 | chr($dataLength >> 48) . |
121 | 121 | chr($dataLength >> 40) . |
122 | 122 | chr($dataLength >> 32) . |
123 | 123 | chr($dataLength >> 24) . |
124 | 124 | chr($dataLength >> 16) . |
125 | - chr($dataLength >> 8) . |
|
125 | + chr($dataLength >> 8) . |
|
126 | 126 | chr($dataLength & 0xFF); |
127 | 127 | } |
128 | 128 | if ($isMasked) { |
129 | - $packet .= $mask . $this->mask($data, $mask); |
|
129 | + $packet .= $mask . $this->mask($data, $mask); |
|
130 | 130 | } else { |
131 | 131 | $packet .= $data; |
132 | 132 | } |
133 | 133 | return $packet; |
134 | 134 | } |
135 | - public function mask ($data, $mask) { |
|
135 | + public function mask($data, $mask) { |
|
136 | 136 | for ($i = 0, $l = strlen($data), $ml = strlen($mask); $i < $l; $i++) { |
137 | - $data[$i] = $data[$i] ^ $mask[$i % $ml] ; |
|
137 | + $data[$i] = $data[$i] ^ $mask[$i % $ml]; |
|
138 | 138 | } |
139 | 139 | return $data; |
140 | 140 | } |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | $dec = 0; |
154 | 154 | $len = strlen($str); |
155 | 155 | |
156 | - for($i = 0; $i < $len; ++$i) { |
|
156 | + for ($i = 0; $i < $len; ++$i) { |
|
157 | 157 | $dec += ord(binarySubstr($str, $i, 1)) * pow(0x100, $len - $i - 1); |
158 | 158 | } |
159 | 159 | |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | |
173 | 173 | if ($len === NULL) { |
174 | 174 | if (strlen($hexstr) % 2) { |
175 | - $hexstr = "0".$hexstr; |
|
175 | + $hexstr = "0" . $hexstr; |
|
176 | 176 | } |
177 | 177 | } else { |
178 | 178 | $hexstr = str_repeat('0', $len * 2 - strlen($hexstr)) . $hexstr; |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | $bytes = strlen($hexstr) / 2; |
182 | 182 | $bin = ''; |
183 | 183 | |
184 | - for($i = 0; $i < $bytes; ++$i) { |
|
184 | + for ($i = 0; $i < $bytes; ++$i) { |
|
185 | 185 | $bin .= chr(hexdec(substr($hexstr, $i * 2, 2))); |
186 | 186 | } |
187 | 187 | |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | } |
210 | 210 | $opcodeName = $this->opcodes[$opcode]; |
211 | 211 | $second = ord(binarySubstr($this->connection->buf, $p++, 1)); // second byte integer (masked, payload length) |
212 | - $fin = (bool) ($first >> 7); |
|
212 | + $fin = (bool) ($first >> 7); |
|
213 | 213 | $isMasked = (bool) ($second >> 7); |
214 | 214 | $dataLength = $second & 0x7f; |
215 | 215 | if ($dataLength === 0x7e) { // 2 bytes-length |
@@ -107,14 +107,12 @@ discard block |
||
107 | 107 | if ($dataLength <= 125) |
108 | 108 | { |
109 | 109 | $packet .= chr($dataLength + $isMaskedInt); |
110 | - } |
|
111 | - elseif ($dataLength <= 65535) |
|
110 | + } elseif ($dataLength <= 65535) |
|
112 | 111 | { |
113 | 112 | $packet .= chr(126 + $isMaskedInt) . // 126 + 128 |
114 | 113 | chr($dataLength >> 8) . |
115 | 114 | chr($dataLength & 0xFF); |
116 | - } |
|
117 | - else { |
|
115 | + } else { |
|
118 | 116 | $packet .= chr(127 + $isMaskedInt) . // 127 + 128 |
119 | 117 | chr($dataLength >> 56) . |
120 | 118 | chr($dataLength >> 48) . |
@@ -218,8 +216,7 @@ discard block |
||
218 | 216 | } |
219 | 217 | $dataLength = $this->bytes2int(binarySubstr($this->connection->buf, $p, 2), false); |
220 | 218 | $p += 2; |
221 | - } |
|
222 | - elseif ($dataLength === 0x7f) { // 4 bytes-length |
|
219 | + } elseif ($dataLength === 0x7f) { // 4 bytes-length |
|
223 | 220 | if ($buflen < $p + 4) { |
224 | 221 | return; // not enough data yet |
225 | 222 | } |
@@ -151,6 +151,7 @@ discard block |
||
151 | 151 | |
152 | 152 | /** |
153 | 153 | * Called when we're going to handshake. |
154 | + * @param string $data |
|
154 | 155 | * @return boolean Handshake status |
155 | 156 | */ |
156 | 157 | |
@@ -197,6 +198,7 @@ discard block |
||
197 | 198 | /** |
198 | 199 | * Called when new data received. |
199 | 200 | * @param string New received data. |
201 | + * @param string $buf |
|
200 | 202 | * @return void |
201 | 203 | */ |
202 | 204 |
@@ -41,16 +41,16 @@ discard block |
||
41 | 41 | return FALSE; |
42 | 42 | } |
43 | 43 | |
44 | - if (!isset($this->protocol)) |
|
45 | - { |
|
46 | - Daemon::$process->log(get_class($this) . '::' . __METHOD__ . ' : Cannot find session-related websocket protocol for client ' . $this->addr) ; |
|
47 | - return FALSE ; |
|
48 | - } |
|
44 | + if (!isset($this->protocol)) |
|
45 | + { |
|
46 | + Daemon::$process->log(get_class($this) . '::' . __METHOD__ . ' : Cannot find session-related websocket protocol for client ' . $this->addr) ; |
|
47 | + return FALSE ; |
|
48 | + } |
|
49 | 49 | |
50 | - $this->protocol->sendFrame($data, $type) ; |
|
51 | - if ($cb) { |
|
52 | - $this->onWriteOnce($cb); |
|
53 | - } |
|
50 | + $this->protocol->sendFrame($data, $type) ; |
|
51 | + if ($cb) { |
|
52 | + $this->onWriteOnce($cb); |
|
53 | + } |
|
54 | 54 | return TRUE; |
55 | 55 | } |
56 | 56 | |
@@ -124,10 +124,10 @@ discard block |
||
124 | 124 | return false; |
125 | 125 | } |
126 | 126 | |
127 | - if (!isset($this->protocol)) { |
|
128 | - Daemon::$process->log(get_class($this) . '::' . __METHOD__ . ' : Cannot find session-related websocket protocol for client "' . $this->addr . '"') ; |
|
129 | - return FALSE ; |
|
130 | - } |
|
127 | + if (!isset($this->protocol)) { |
|
128 | + Daemon::$process->log(get_class($this) . '::' . __METHOD__ . ' : Cannot find session-related websocket protocol for client "' . $this->addr . '"') ; |
|
129 | + return FALSE ; |
|
130 | + } |
|
131 | 131 | |
132 | 132 | if ($this->protocol->onHandshake() === FALSE) { |
133 | 133 | return FALSE ; |
@@ -305,13 +305,13 @@ discard block |
||
305 | 305 | } |
306 | 306 | if ($this->state === self::STATE_HANDSHAKED) |
307 | 307 | { |
308 | - if (!isset($this->protocol)) |
|
309 | - { |
|
310 | - Daemon::$process->log(get_class($this) . '::' . __METHOD__ . ' : Cannot find session-related websocket protocol for client "' . $this->addr . '"'); |
|
311 | - $this->finish(); |
|
312 | - return; |
|
313 | - } |
|
314 | - $this->protocol->onRead(); |
|
308 | + if (!isset($this->protocol)) |
|
309 | + { |
|
310 | + Daemon::$process->log(get_class($this) . '::' . __METHOD__ . ' : Cannot find session-related websocket protocol for client "' . $this->addr . '"'); |
|
311 | + $this->finish(); |
|
312 | + return; |
|
313 | + } |
|
314 | + $this->protocol->onRead(); |
|
315 | 315 | } |
316 | 316 | } |
317 | 317 | } |
@@ -43,11 +43,11 @@ discard block |
||
43 | 43 | |
44 | 44 | if (!isset($this->protocol)) |
45 | 45 | { |
46 | - Daemon::$process->log(get_class($this) . '::' . __METHOD__ . ' : Cannot find session-related websocket protocol for client ' . $this->addr) ; |
|
47 | - return FALSE ; |
|
46 | + Daemon::$process->log(get_class($this) . '::' . __METHOD__ . ' : Cannot find session-related websocket protocol for client ' . $this->addr); |
|
47 | + return FALSE; |
|
48 | 48 | } |
49 | 49 | |
50 | - $this->protocol->sendFrame($data, $type) ; |
|
50 | + $this->protocol->sendFrame($data, $type); |
|
51 | 51 | if ($cb) { |
52 | 52 | $this->onWriteOnce($cb); |
53 | 53 | } |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | public function onHandshake() { |
94 | 94 | |
95 | 95 | $e = explode('/', $this->server['DOCUMENT_URI']); |
96 | - $routeName = isset($e[1])?$e[1]:''; |
|
96 | + $routeName = isset($e[1]) ? $e[1] : ''; |
|
97 | 97 | |
98 | 98 | if (!isset($this->pool->routes[$routeName])) { |
99 | 99 | if (Daemon::$config->logerrors->value) { |
@@ -125,12 +125,12 @@ discard block |
||
125 | 125 | } |
126 | 126 | |
127 | 127 | if (!isset($this->protocol)) { |
128 | - Daemon::$process->log(get_class($this) . '::' . __METHOD__ . ' : Cannot find session-related websocket protocol for client "' . $this->addr . '"') ; |
|
129 | - return FALSE ; |
|
128 | + Daemon::$process->log(get_class($this) . '::' . __METHOD__ . ' : Cannot find session-related websocket protocol for client "' . $this->addr . '"'); |
|
129 | + return FALSE; |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | if ($this->protocol->onHandshake() === FALSE) { |
133 | - return FALSE ; |
|
133 | + return FALSE; |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | return TRUE; |
@@ -157,14 +157,14 @@ discard block |
||
157 | 157 | public function handshake($data) { |
158 | 158 | |
159 | 159 | if (!$this->onHandshake()) { |
160 | - Daemon::$process->log(get_class($this) . '::' . __METHOD__ . ' : Cannot handshake session for client "' . $this->addr . '"') ; |
|
160 | + Daemon::$process->log(get_class($this) . '::' . __METHOD__ . ' : Cannot handshake session for client "' . $this->addr . '"'); |
|
161 | 161 | $this->finish(); |
162 | 162 | return false; |
163 | 163 | } |
164 | 164 | |
165 | 165 | if (!isset($this->protocol)) { |
166 | - Daemon::$process->log(get_class($this) . '::' . __METHOD__ . ' : Cannot find session-related websocket protocol for client "' . $this->addr . '"') ; |
|
167 | - $this->finish() ; |
|
166 | + Daemon::$process->log(get_class($this) . '::' . __METHOD__ . ' : Cannot find session-related websocket protocol for client "' . $this->addr . '"'); |
|
167 | + $this->finish(); |
|
168 | 168 | return false; |
169 | 169 | } |
170 | 170 | |
@@ -176,17 +176,17 @@ discard block |
||
176 | 176 | } |
177 | 177 | |
178 | 178 | if (!$handshake) { |
179 | - Daemon::$process->log(get_class($this) . '::' . __METHOD__ . ' : Handshake protocol failure for client "' . $this->addr . '"') ; |
|
180 | - $this->finish() ; |
|
181 | - return false ; |
|
179 | + Daemon::$process->log(get_class($this) . '::' . __METHOD__ . ' : Handshake protocol failure for client "' . $this->addr . '"'); |
|
180 | + $this->finish(); |
|
181 | + return false; |
|
182 | 182 | } |
183 | 183 | if ($this->write($handshake)) { |
184 | - if (is_callable(array($this->upstream, 'onHandshake'))) { |
|
184 | + if (is_callable(array($this->upstream, 'onHandshake'))) { |
|
185 | 185 | $this->upstream->onHandshake(); |
186 | 186 | } |
187 | 187 | } |
188 | 188 | else { |
189 | - Daemon::$process->log(get_class($this) . '::' . __METHOD__ . ' : Handshake send failure for client "' . $this->addr . '"') ; |
|
189 | + Daemon::$process->log(get_class($this) . '::' . __METHOD__ . ' : Handshake send failure for client "' . $this->addr . '"'); |
|
190 | 190 | $this->finish(); |
191 | 191 | return false; |
192 | 192 | } |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | |
203 | 203 | public function stdin($buf) { |
204 | 204 | $this->buf .= $buf; |
205 | - if ($this->state === self::STATE_ROOT) { |
|
205 | + if ($this->state === self::STATE_ROOT) { |
|
206 | 206 | if (strpos($this->buf, "<policy-file-request/>\x00") !== false) { |
207 | 207 | $FP = FlashPolicyServer::getInstance(); |
208 | 208 | if ($FP && $FP->policyData) { |
@@ -246,14 +246,14 @@ discard block |
||
246 | 246 | // ---------------------------------------------------------- |
247 | 247 | if (isset($this->server['HTTP_SEC_WEBSOCKET_VERSION'])) { // HYBI |
248 | 248 | if ($this->server['HTTP_SEC_WEBSOCKET_VERSION'] == '8') { // Version 8 (FF7, Chrome14) |
249 | - $this->protocol = new WebSocketProtocolV13($this) ; |
|
249 | + $this->protocol = new WebSocketProtocolV13($this); |
|
250 | 250 | } |
251 | 251 | elseif ($this->server['HTTP_SEC_WEBSOCKET_VERSION'] == '13') { // newest protocol |
252 | 252 | $this->protocol = new WebSocketProtocolV13($this); |
253 | 253 | } |
254 | 254 | else |
255 | 255 | { |
256 | - Daemon::$process->log(get_class($this) . '::' . __METHOD__ . " : Websocket protocol version " . $this->server['HTTP_SEC_WEBSOCKET_VERSION'] . ' is not yet supported for client "' . $this->addr . '"') ; |
|
256 | + Daemon::$process->log(get_class($this) . '::' . __METHOD__ . " : Websocket protocol version " . $this->server['HTTP_SEC_WEBSOCKET_VERSION'] . ' is not yet supported for client "' . $this->addr . '"'); |
|
257 | 257 | |
258 | 258 | $this->finish(); |
259 | 259 | return; |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | $this->protocol = new WebSocketProtocolVE($this); |
264 | 264 | } |
265 | 265 | else { // Defaulting to HIXIE (Safari5 and many non-browser clients...) |
266 | - $this->protocol = new WebSocketProtocolV0($this) ; |
|
266 | + $this->protocol = new WebSocketProtocolV0($this); |
|
267 | 267 | } |
268 | 268 | // ---------------------------------------------------------- |
269 | 269 | // End of protocol discovery |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | $this->server['SCRIPT_NAME'] = $this->server['DOCUMENT_URI'] = isset($u['path']) ? $u['path'] : '/'; |
284 | 284 | $this->server['SERVER_PROTOCOL'] = isset($e[2]) ? trim($e[2]) : ''; |
285 | 285 | |
286 | - list($this->server['REMOTE_ADDR'],$this->server['REMOTE_PORT']) = explode(':', $this->addr); |
|
286 | + list($this->server['REMOTE_ADDR'], $this->server['REMOTE_PORT']) = explode(':', $this->addr); |
|
287 | 287 | } |
288 | 288 | else |
289 | 289 | { |
@@ -184,8 +184,7 @@ discard block |
||
184 | 184 | if (is_callable(array($this->upstream, 'onHandshake'))) { |
185 | 185 | $this->upstream->onHandshake(); |
186 | 186 | } |
187 | - } |
|
188 | - else { |
|
187 | + } else { |
|
189 | 188 | Daemon::$process->log(get_class($this) . '::' . __METHOD__ . ' : Handshake send failure for client "' . $this->addr . '"') ; |
190 | 189 | $this->finish(); |
191 | 190 | return false; |
@@ -247,29 +246,24 @@ discard block |
||
247 | 246 | if (isset($this->server['HTTP_SEC_WEBSOCKET_VERSION'])) { // HYBI |
248 | 247 | if ($this->server['HTTP_SEC_WEBSOCKET_VERSION'] == '8') { // Version 8 (FF7, Chrome14) |
249 | 248 | $this->protocol = new WebSocketProtocolV13($this) ; |
250 | - } |
|
251 | - elseif ($this->server['HTTP_SEC_WEBSOCKET_VERSION'] == '13') { // newest protocol |
|
249 | + } elseif ($this->server['HTTP_SEC_WEBSOCKET_VERSION'] == '13') { // newest protocol |
|
252 | 250 | $this->protocol = new WebSocketProtocolV13($this); |
253 | - } |
|
254 | - else |
|
251 | + } else |
|
255 | 252 | { |
256 | 253 | Daemon::$process->log(get_class($this) . '::' . __METHOD__ . " : Websocket protocol version " . $this->server['HTTP_SEC_WEBSOCKET_VERSION'] . ' is not yet supported for client "' . $this->addr . '"') ; |
257 | 254 | |
258 | 255 | $this->finish(); |
259 | 256 | return; |
260 | 257 | } |
261 | - } |
|
262 | - elseif (!isset($this->server['HTTP_SEC_WEBSOCKET_KEY1']) || !isset($this->server['HTTP_SEC_WEBSOCKET_KEY2'])) { |
|
258 | + } elseif (!isset($this->server['HTTP_SEC_WEBSOCKET_KEY1']) || !isset($this->server['HTTP_SEC_WEBSOCKET_KEY2'])) { |
|
263 | 259 | $this->protocol = new WebSocketProtocolVE($this); |
264 | - } |
|
265 | - else { // Defaulting to HIXIE (Safari5 and many non-browser clients...) |
|
260 | + } else { // Defaulting to HIXIE (Safari5 and many non-browser clients...) |
|
266 | 261 | $this->protocol = new WebSocketProtocolV0($this) ; |
267 | 262 | } |
268 | 263 | // ---------------------------------------------------------- |
269 | 264 | // End of protocol discovery |
270 | 265 | // ---------------------------------------------------------- |
271 | - } |
|
272 | - elseif (!$this->firstline) |
|
266 | + } elseif (!$this->firstline) |
|
273 | 267 | { |
274 | 268 | $this->firstline = true; |
275 | 269 | $e = explode(' ', $l); |
@@ -284,8 +278,7 @@ discard block |
||
284 | 278 | $this->server['SERVER_PROTOCOL'] = isset($e[2]) ? trim($e[2]) : ''; |
285 | 279 | |
286 | 280 | list($this->server['REMOTE_ADDR'],$this->server['REMOTE_PORT']) = explode(':', $this->addr); |
287 | - } |
|
288 | - else |
|
281 | + } else |
|
289 | 282 | { |
290 | 283 | $e = explode(': ', $l); |
291 | 284 |
@@ -17,6 +17,9 @@ discard block |
||
17 | 17 | xml_set_character_data_handler($this->parser, 'charXML'); |
18 | 18 | } |
19 | 19 | |
20 | + /** |
|
21 | + * @param string $ns |
|
22 | + */ |
|
20 | 23 | public function setDefaultNS($ns) { |
21 | 24 | $this->default_ns = $ns; |
22 | 25 | } |
@@ -164,8 +167,7 @@ discard block |
||
164 | 167 | * Add ID Handler |
165 | 168 | * |
166 | 169 | * @param integer $id |
167 | - * @param string $pointer |
|
168 | - * @param string $obj |
|
170 | + * @param Closure $cb |
|
169 | 171 | */ |
170 | 172 | public function addIdHandler($id, $cb) { |
171 | 173 | if ($cb === null) { |
@@ -196,8 +198,8 @@ discard block |
||
196 | 198 | * Add XPath Handler |
197 | 199 | * |
198 | 200 | * @param string $xpath |
199 | - * @param string $pointer |
|
200 | 201 | * @param |
202 | + * @param Closure $cb |
|
201 | 203 | */ |
202 | 204 | public function addXPathHandler($xpath, $cb, $obj = null) { |
203 | 205 | if (preg_match_all("/\(?{[^\}]+}\)?(\/?)[^\/]+/", $xpath, $regs)) { |
@@ -142,10 +142,10 @@ |
||
142 | 142 | |
143 | 143 | |
144 | 144 | /** |
145 | - * Get next ID |
|
146 | - * |
|
147 | - * @return integer |
|
148 | - */ |
|
145 | + * Get next ID |
|
146 | + * |
|
147 | + * @return integer |
|
148 | + */ |
|
149 | 149 | public function getId() { |
150 | 150 | $this->lastid++; |
151 | 151 | return $this->lastid; |
@@ -50,24 +50,24 @@ discard block |
||
50 | 50 | $this->current_ns[$this->xml_depth] = $attr['XMLNS']; |
51 | 51 | } else { |
52 | 52 | $this->current_ns[$this->xml_depth] = $this->current_ns[$this->xml_depth - 1]; |
53 | - if(!$this->current_ns[$this->xml_depth]) $this->current_ns[$this->xml_depth] = $this->default_ns; |
|
53 | + if (!$this->current_ns[$this->xml_depth]) $this->current_ns[$this->xml_depth] = $this->default_ns; |
|
54 | 54 | } |
55 | 55 | $ns = $this->current_ns[$this->xml_depth]; |
56 | - foreach($attr as $key => $value) { |
|
57 | - if(strstr($key, ':')) { |
|
56 | + foreach ($attr as $key => $value) { |
|
57 | + if (strstr($key, ':')) { |
|
58 | 58 | $key = explode(':', $key); |
59 | 59 | $key = $key[1]; |
60 | 60 | $this->ns_map[$key] = $value; |
61 | 61 | } |
62 | 62 | } |
63 | - if(!strstr($name, ":") === false) |
|
63 | + if (!strstr($name, ":") === false) |
|
64 | 64 | { |
65 | 65 | $name = explode(':', $name); |
66 | 66 | $ns = $this->ns_map[$name[0]]; |
67 | 67 | $name = $name[1]; |
68 | 68 | } |
69 | 69 | $obj = new XMLStream_Object($name, $ns, $attr); |
70 | - if($this->xml_depth > 1) { |
|
70 | + if ($this->xml_depth > 1) { |
|
71 | 71 | $this->xmlobj[$this->xml_depth - 1]->subs[] = $obj; |
72 | 72 | } |
73 | 73 | $this->xmlobj[$this->xml_depth] = $obj; |
@@ -84,14 +84,14 @@ discard block |
||
84 | 84 | public function endXML($parser, $name) { |
85 | 85 | --$this->xml_depth; |
86 | 86 | if ($this->xml_depth == 1) { |
87 | - foreach($this->xpathhandlers as $handler) { |
|
87 | + foreach ($this->xpathhandlers as $handler) { |
|
88 | 88 | if (is_array($this->xmlobj) && array_key_exists(2, $this->xmlobj)) { |
89 | 89 | $searchxml = $this->xmlobj[2]; |
90 | 90 | $nstag = array_shift($handler[0]); |
91 | 91 | if (($nstag[0] == null or $searchxml->ns == $nstag[0]) and ($nstag[1] == "*" or $nstag[1] == $searchxml->name)) { |
92 | - foreach($handler[0] as $nstag) { |
|
93 | - if ($searchxml !== null and $searchxml->hasSub($nstag[1], $ns=$nstag[0])) { |
|
94 | - $searchxml = $searchxml->sub($nstag[1], $ns=$nstag[0]); |
|
92 | + foreach ($handler[0] as $nstag) { |
|
93 | + if ($searchxml !== null and $searchxml->hasSub($nstag[1], $ns = $nstag[0])) { |
|
94 | + $searchxml = $searchxml->sub($nstag[1], $ns = $nstag[0]); |
|
95 | 95 | } else { |
96 | 96 | $searchxml = null; |
97 | 97 | break; |
@@ -106,23 +106,23 @@ discard block |
||
106 | 106 | } |
107 | 107 | } |
108 | 108 | } |
109 | - foreach($this->idhandlers as $id => $handler) { |
|
110 | - if(array_key_exists('id', $this->xmlobj[2]->attrs) and $this->xmlobj[2]->attrs['id'] == $id) { |
|
109 | + foreach ($this->idhandlers as $id => $handler) { |
|
110 | + if (array_key_exists('id', $this->xmlobj[2]->attrs) and $this->xmlobj[2]->attrs['id'] == $id) { |
|
111 | 111 | call_user_func($handler, $this->xmlobj[2]); |
112 | 112 | #id handlers are only used once |
113 | 113 | unset($this->idhandlers[$id]); |
114 | 114 | break; |
115 | 115 | } |
116 | 116 | } |
117 | - if(is_array($this->xmlobj)) { |
|
117 | + if (is_array($this->xmlobj)) { |
|
118 | 118 | $this->xmlobj = array_slice($this->xmlobj, 0, 1); |
119 | - if(isset($this->xmlobj[0]) && $this->xmlobj[0] instanceof XMLStream_Object) { |
|
119 | + if (isset($this->xmlobj[0]) && $this->xmlobj[0] instanceof XMLStream_Object) { |
|
120 | 120 | $this->xmlobj[0]->subs = null; |
121 | 121 | } |
122 | 122 | } |
123 | 123 | unset($this->xmlobj[2]); |
124 | 124 | } |
125 | - if($this->xml_depth == 0) { |
|
125 | + if ($this->xml_depth == 0) { |
|
126 | 126 | $this->event('streamEnd'); |
127 | 127 | } |
128 | 128 | } |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | * @param string $data |
136 | 136 | */ |
137 | 137 | public function charXML($parser, $data) { |
138 | - if(array_key_exists($this->xml_depth, $this->xmlobj)) { |
|
138 | + if (array_key_exists($this->xml_depth, $this->xmlobj)) { |
|
139 | 139 | $this->xmlobj[$this->xml_depth]->data .= $data; |
140 | 140 | } |
141 | 141 | } |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | * |
157 | 157 | * @return integer |
158 | 158 | */ |
159 | - public function useSSL($use=true) { |
|
159 | + public function useSSL($use = true) { |
|
160 | 160 | $this->use_ssl = $use; |
161 | 161 | } |
162 | 162 | |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | } else { |
206 | 206 | $ns_tags = array($xpath); |
207 | 207 | } |
208 | - foreach($ns_tags as $ns_tag) { |
|
208 | + foreach ($ns_tags as $ns_tag) { |
|
209 | 209 | list($l, $r) = explode("}", $ns_tag); |
210 | 210 | if ($r != null) { |
211 | 211 | $xpart = array(substr($l, 1), $r); |
@@ -267,8 +267,8 @@ discard block |
||
267 | 267 | public function __construct($name, $ns = '', $attrs = array(), $data = '') { |
268 | 268 | $this->name = strtolower($name); |
269 | 269 | $this->ns = $ns; |
270 | - if(is_array($attrs) && count($attrs)) { |
|
271 | - foreach($attrs as $key => $value) { |
|
270 | + if (is_array($attrs) && count($attrs)) { |
|
271 | + foreach ($attrs as $key => $value) { |
|
272 | 272 | $this->attrs[strtolower($key)] = $value; |
273 | 273 | } |
274 | 274 | } |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | */ |
283 | 283 | public function printObj($depth = 0) { |
284 | 284 | $s = str_repeat("\t", $depth) . $this->name . " " . $this->ns . ' ' . $this->data . "\n"; |
285 | - foreach($this->subs as $sub) { |
|
285 | + foreach ($this->subs as $sub) { |
|
286 | 286 | $s .= $sub->printObj($depth + 1); |
287 | 287 | } |
288 | 288 | return $s; |
@@ -295,14 +295,14 @@ discard block |
||
295 | 295 | */ |
296 | 296 | public function toString($str = '') { |
297 | 297 | $str .= "<{$this->name} xmlns='{$this->ns}' "; |
298 | - foreach($this->attrs as $key => $value) { |
|
299 | - if($key != 'xmlns') { |
|
298 | + foreach ($this->attrs as $key => $value) { |
|
299 | + if ($key != 'xmlns') { |
|
300 | 300 | $value = htmlspecialchars($value); |
301 | 301 | $str .= "$key='$value' "; |
302 | 302 | } |
303 | 303 | } |
304 | 304 | $str .= ">"; |
305 | - foreach($this->subs as $sub) { |
|
305 | + foreach ($this->subs as $sub) { |
|
306 | 306 | $str .= $sub->toString(); |
307 | 307 | } |
308 | 308 | $body = htmlspecialchars($this->data); |
@@ -317,8 +317,8 @@ discard block |
||
317 | 317 | * @return boolean |
318 | 318 | */ |
319 | 319 | public function hasSub($name, $ns = null) { |
320 | - foreach($this->subs as $sub) { |
|
321 | - if(($name == "*" or $sub->name == $name) and ($ns == null or $sub->ns == $ns)) return true; |
|
320 | + foreach ($this->subs as $sub) { |
|
321 | + if (($name == "*" or $sub->name == $name) and ($ns == null or $sub->ns == $ns)) return true; |
|
322 | 322 | } |
323 | 323 | return false; |
324 | 324 | } |
@@ -332,8 +332,8 @@ discard block |
||
332 | 332 | */ |
333 | 333 | public function sub($name, $attrs = null, $ns = null) { |
334 | 334 | #TODO attrs is ignored |
335 | - foreach($this->subs as $sub) { |
|
336 | - if($sub->name == $name and ($ns == null or $sub->ns == $ns)) { |
|
335 | + foreach ($this->subs as $sub) { |
|
336 | + if ($sub->name == $name and ($ns == null or $sub->ns == $ns)) { |
|
337 | 337 | return $sub; |
338 | 338 | } |
339 | 339 | } |
@@ -50,7 +50,9 @@ discard block |
||
50 | 50 | $this->current_ns[$this->xml_depth] = $attr['XMLNS']; |
51 | 51 | } else { |
52 | 52 | $this->current_ns[$this->xml_depth] = $this->current_ns[$this->xml_depth - 1]; |
53 | - if(!$this->current_ns[$this->xml_depth]) $this->current_ns[$this->xml_depth] = $this->default_ns; |
|
53 | + if(!$this->current_ns[$this->xml_depth]) { |
|
54 | + $this->current_ns[$this->xml_depth] = $this->default_ns; |
|
55 | + } |
|
54 | 56 | } |
55 | 57 | $ns = $this->current_ns[$this->xml_depth]; |
56 | 58 | foreach($attr as $key => $value) { |
@@ -318,7 +320,9 @@ discard block |
||
318 | 320 | */ |
319 | 321 | public function hasSub($name, $ns = null) { |
320 | 322 | foreach($this->subs as $sub) { |
321 | - if(($name == "*" or $sub->name == $name) and ($ns == null or $sub->ns == $ns)) return true; |
|
323 | + if(($name == "*" or $sub->name == $name) and ($ns == null or $sub->ns == $ns)) { |
|
324 | + return true; |
|
325 | + } |
|
322 | 326 | } |
323 | 327 | return false; |
324 | 328 | } |