/**
  * @param Request $request
  * @param $processor
  * @param string $protocol
  * @return Response
  */
 public static function make($request, $processor, $protocol)
 {
     $readTransport = new TMemoryBuffer($request->getContent());
     $writeTransport = new TMemoryBuffer();
     switch ($protocol) {
         case 'json':
             $readProtocol = new TJSONProtocol($readTransport);
             $writeProtocol = new TJSONProtocol($writeTransport);
             break;
         case 'binary':
             $readProtocol = new TBinaryProtocol($readTransport);
             $writeProtocol = new TBinaryProtocol($writeTransport);
             break;
         case 'compact':
             $readProtocol = new TCompactProtocol($readTransport);
             $writeProtocol = new TCompactProtocol($writeTransport);
             break;
         default:
             throw new UnexpectedValueException();
     }
     $readTransport->open();
     $writeTransport->open();
     $processor->process($readProtocol, $writeProtocol);
     $readTransport->close();
     $writeTransport->close();
     $content = $writeTransport->getBuffer();
     return new Response($content, 200, ['Content-Type' => 'application/x-thrift', 'Access-Control-Allow-Origin' => $request->header('origin')]);
 }
示例#2
0
 public static function serialize($object)
 {
     $transport = new TMemoryBuffer();
     $protocol = new TBinaryProtocolAccelerated($transport);
     if (function_exists('thrift_protocol_write_binary')) {
         thrift_protocol_write_binary($protocol, $object->getName(), TMessageType::REPLY, $object, 0, $protocol->isStrictWrite());
         $protocol->readMessageBegin($unused_name, $unused_type, $unused_seqid);
     } else {
         $object->write($protocol);
     }
     $protocol->getTransport()->flush();
     return $transport->getBuffer();
 }
示例#3
0
 public function writeContextSerialize()
 {
     global $context;
     if (empty($context)) {
         return '';
     }
     $obj = new \Thrift\ContextSeralize($context);
     $transObj = new \Thrift\Transport\TMemoryBuffer();
     $protocol = new \Thrift\Protocol\TBinaryProtocol($transObj);
     $obj->write($protocol);
     return $transObj->getBuffer();
 }