public function _set_to($value) { if (!$value instanceof Jid) { $value = new Jid($value); } $this->_to = $value; $this['to'] = $value->__toString(); }
/** * Helper, gets jid from packet. * * @return Jid */ public function _get_jid() { $jid = $this['from']; $item = $this->xpath('//user:item[@jid]', ['user' => 'http://jabber.org/protocol/muc#user']); if (!empty($item)) { $jid = $item[0]['jid']; } if (!isset($this->_jid) || $this->_jid->__toString() != $jid) { $this->_jid = new Jid($jid); } return $this->_jid; }
/** * Gets user affiliation list. * * @param Jid $room Jid of room to query. * @param string $affiliation Affiliation type. * @param callable $delegate Delegate to run after proper packet came. * Delegate takes one argument (packet) of type SimpleXMLElement. * * @internal Plugins should use Room::affiliationList() instead of that. * * @throws \InvalidArgumentException */ public function affiliationList(Jid $room, $affiliation, callable $delegate) { if (!in_array($affiliation, array('none', 'outcast', 'member', 'admin', 'owner'))) { throw new \InvalidArgumentException('affiliation'); } $xml = new xmlBranch("iq"); $id = uniqid('affiliate_'); $xml->addAttribute("type", "get")->addAttribute('from', $this->jid->__toString())->addAttribute("to", $room->__toString())->addAttribute("id", $id); $xml->addChild(new xmlBranch("query")); $xml->query[0]->addAttribute("xmlns", "http://jabber.org/protocol/muc#admin"); $xml->query[0]->addChild(new xmlBranch("item")); $xml->query[0]->item[0]->addAttribute("affiliation", $affiliation); $this->write($xml->asXml()); $this->wait('iq', $id, $delegate); }