/** * @param NodeInterface $node * @return $this */ protected function writeInternal(NodeInterface $node) { $len = 1; if ($node->getAttributes() != null) { $len += count($node->getAttributes()) * 2; } if (count($node->getChildren()) > 0) { $len += 1; } if (strlen($node->getData()) > 0) { $len += 1; } $this->writeListStart($len); $this->writeString($node->getName()); $this->writeAttributes($node->getAttributes()); if (strlen($node->getData()) > 0) { $this->writeBytes($node->getData()); } if ($node->getChildren()) { $this->writeListStart(count($node->getChildren())); foreach ($node->getChildren() as $child) { $this->writeInternal($child); } } return $this; }
/** * @param Client $client * @param NodeInterface $node */ protected function sendNotificationAck(Client $client, NodeInterface $node) { $ackNode = new Node(); if ($node->hasAttribute("to")) { $ackNode->setAttribute('from', $node->getAttribute("to")); } if ($node->hasAttribute("participant")) { $ackNode->setAttribute('participant', $node->getAttribute("participant")); } $ackNode->setAttribute('to', $node->getAttribute("from")); $ackNode->setAttribute('class', $node->getName()); $ackNode->setAttribute('id', $node->getAttribute("id")); $ackNode->setAttribute('type', $node->getAttribute("type")); $client->sendNode($ackNode); }
/** * @param NodeInterface $node * @return $this */ protected function injectNodeId(NodeInterface $node) { $prefix = $node->getAttribute('id') ?: ''; $node->setAttribute('id', $prefix . $node->getName() . '-' . time() . '-' . $this->messageCounter++); return $this; }