Example #1
0
 public function _run(Query $query, $options, &$profile)
 {
     if (isset($options) && !is_array($options)) {
         throw new RqlDriverError("Options must be an array.");
     }
     if (!$this->isOpen()) {
         throw new RqlDriverError("Not connected.");
     }
     // Grab PHP-RQL specific options
     $toNativeOptions = array();
     foreach (array('binaryFormat', 'timeFormat') as $opt) {
         if (isset($options) && isset($options[$opt])) {
             $toNativeOptions[$opt] = $options[$opt];
             unset($options[$opt]);
         }
     }
     // Generate a token for the request
     $token = $this->generateToken();
     // Send the request
     $jsonTerm = $query->_getJSONTerm();
     $globalOptargs = array();
     if (isset($this->defaultDb)) {
         $globalOptargs['db'] = $this->defaultDb->_getJSONTerm();
     }
     if (isset($options)) {
         foreach ($options as $key => $value) {
             $globalOptargs[$key] = nativeToDatum($value)->_getJSONTerm();
         }
     }
     $jsonQuery = array(pb\Query_QueryType::PB_START, $jsonTerm, (object) $globalOptargs);
     $this->sendQuery($token, $jsonQuery);
     if (isset($options) && isset($options['noreply']) && $options['noreply'] === true) {
         return null;
     } else {
         // Await the response
         $response = $this->receiveResponse($token, $query);
         if ($response['t'] == pb\Response_ResponseType::PB_SUCCESS_PARTIAL) {
             $this->activeTokens[$token] = true;
         }
         if (isset($response['p'])) {
             $profile = decodedJSONToDatum($response['p'])->toNative($toNativeOptions);
         }
         if ($response['t'] == pb\Response_ResponseType::PB_SUCCESS_ATOM) {
             return $this->createDatumFromResponse($response)->toNative($toNativeOptions);
         } else {
             return $this->createCursorFromResponse($response, $token, $response['n'], $toNativeOptions);
         }
     }
 }