Example #1
0
 public function run(Query $query, $options = array(), &$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
     $globalOptargs = $this->convertOptions($options);
     if (isset($this->defaultDb) && !isset($options['db'])) {
         $globalOptargs['db'] = $this->defaultDb->encodeServerRequest();
     }
     $jsonQuery = array(QueryQueryType::PB_START, $query->encodeServerRequest(), (object) $globalOptargs);
     $this->sendQuery($token, $jsonQuery);
     if (isset($options['noreply']) && $options['noreply'] === true) {
         return null;
     }
     // Await the response
     $response = $this->receiveResponse($token, $query);
     if ($response['t'] == ResponseResponseType::PB_SUCCESS_PARTIAL) {
         $this->activeTokens[$token] = true;
     }
     if (isset($response['p'])) {
         $profile = $this->decodedJSONToDatum($response['p'])->toNative($toNativeOptions);
     }
     if ($response['t'] == ResponseResponseType::PB_SUCCESS_ATOM) {
         return $this->createDatumFromResponse($response)->toNative($toNativeOptions);
     } else {
         return $this->createCursorFromResponse($response, $token, $response['n'], $toNativeOptions);
     }
 }