public function sendBatch($reqs)
    {
        $arr = array();
        $ids = array();
        $all_notify = true;
        foreach ($reqs as $req) {
            if ($req->id) {
                $all_notify = false;
                $ids[] = $req->id;
            }
            $arr[] = $req->getArray();
        }
        $response = $this->send(json_encode($arr), $all_notify);

        // no response if batch is all notifications
        if ($all_notify) {
            return true;
        }

        // check for missing ids and return responses in order of requests
        $ordered_response = array();
        foreach ($ids as $id) {
            if (array_key_exists($id, $response)) {
                $ordered_response[] = $response[$id];
                unset($response[$id]);
            } else {
                throw new Clientside\Exception("Missing id in response");
            }
        }

        // check for extra ids in response
        if (count($response) > 0) {
            throw new Clientside\Exception("Extra id(s) in response");
        }

        return $ordered_response;
    }
public function sendBatch($reqs)
    {
        $arr = array();
        $ids = array();
        $all_notify = true;
        foreach ($reqs as $req) {
            if ($req->id) {
                $all_notify = false;
                $ids[] = $req->id;
            }
            $arr[] = $req->getArray();
        }
        $response = $this->send(json_encode($arr), $all_notify);

        // no response if batch is all notifications
        if ($all_notify) {
            return true;
        }

        // check for missing ids and return responses in order of requests
        $ordered_response = array();
        foreach ($ids as $id) {
            if (array_key_exists($id, $response)) {
                $ordered_response[] = $response[$id];
                unset($response[$id]);
            } else {
                throw new Clientside\Exception("Missing id in response");
            }
        }

        // check for extra ids in response
        if (count($response) > 0) {
            throw new Clientside\Exception("Extra id(s) in response");
        }

        return $ordered_response;
    }
public function sendBatch ( $ reqs ) { $ arr = array ( ) ; $ ids = array ( ) ; $ all_notify = true ; foreach ( $ reqs as $ req ) { if ( $ req -> id ) { $ all_notify = false ; $ ids [ ] = $ req -> id ; } $ arr [ ] = $ req -> getArray ( ) ; } $ response = $ this -> send ( json_encode ( $ arr ) , $ all_notify ) ; // no response if batch is all notifications if ( $ all_notify ) { return true ; } // check for missing ids and return responses in order of requests $ ordered_response = array ( ) ; foreach ( $ ids as $ id ) { if ( array_key_exists ( $ id , $ response ) ) { $ ordered_response [ ] = $ response [ $ id ] ; unset ( $ response [ $ id ] ) ; } else { throw new Clientside \ Exception ( "Missing id in response" ) ; } } // check for extra ids in response if ( count ( $ response ) > 0 ) { throw new Clientside \ Exception ( "Extra id(s) in response" ) ; } return $ ordered_response ; }
send an array of request objects as a batch
send an array of request objects as a batch