public function handleData(&$data) { if (!$this->connected) { $data = $this->readHandshakeResponse($data); } $frames = array(); while ($frame = WebSocketFrame::decode($data)) { if (WebSocketOpcode::isControlFrame($frame->getType())) { $this->processControlFrame($frame); } else { $this->processMessageFrame($frame); } $frames[] = $frame; } return $frames; }