PHPDaemon\XMLStream\XMLStream::addIdHandler PHP Method

addIdHandler() public method

Add ID Handler
public addIdHandler ( integer $id, callable $cb )
$id integer
$cb callable
    public function addIdHandler($id, $cb)
    {
        if ($cb === null) {
            return;
        }
        $this->idhandlers[$id] = $cb;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * @TODO DESCR
  * @param string   $jid
  * @param callable $cb
  * @callback $cb ( )
  */
 public function getVCard($jid = null, $cb)
 {
     $id = $this->getId();
     $this->xml->addIdHandler($id, function ($xml) use($cb) {
         $vcard = [];
         $vcardXML = $xml->sub('vcard');
         foreach ($vcardXML->subs as $sub) {
             if ($sub->subs) {
                 $vcard[$sub->name] = [];
                 foreach ($sub->subs as $sub_child) {
                     $vcard[$sub->name][$sub_child->name] = $sub_child->data;
                 }
             } else {
                 $vcard[$sub->name] = $sub->data;
             }
         }
         $vcard['from'] = $xml->attrs['from'];
         call_user_func($cb, $vcard);
     });
     $id = htmlspecialchars($id);
     $jid = htmlspecialchars($jid);
     if ($jid) {
         $this->send('<iq type="get" id="' . $id . '" to="' . $jid . '"><vCard xmlns="vcard-temp" /></iq>');
     } else {
         $this->send('<iq type="get" id="' . $id . '"><vCard xmlns="vcard-temp" /></iq>');
     }
 }