diff --git a/src/Platform/Endpoint.php b/src/Platform/Endpoint.php index 799c98b..32d9376 100644 --- a/src/Platform/Endpoint.php +++ b/src/Platform/Endpoint.php @@ -7,6 +7,7 @@ namespace Platform; use Thrift\Protocol\TBinaryProtocol; +use Thrift\Protocol\TJSONProtocol; use Thrift\Transport\TBufferedTransport; use Thrift\Transport\TPhpStream; use Thrift\Transport\THttpClient; @@ -15,6 +16,8 @@ class Endpoint { protected $config; protected $transport = null; + + const PROTOCOL_JSON = 'JSON'; public function __construct(EndpointConfig $config) { @@ -58,10 +61,16 @@ public function process() ); /** - * Инициализация бинарного прототокола + * Пока наш клиент не умеет общаться по бинарному протоколу, + * инициализируем в зависимости от наличия заголовка */ + if ( isset($_SERVER['HTTP_X_THRIFT_PROTOCOL']) && $_SERVER['HTTP_X_THRIFT_PROTOCOL'] === self::PROTOCOL_JSON ) + { + $protocol = new TJSONProtocol($transport); + } else { + $protocol = new TBinaryProtocol($transport, true, true); + } - $protocol = new TBinaryProtocol($transport, true, true); $transport->open(); /** @@ -111,7 +120,17 @@ public function getClient($host = '127.0.0.1', $port = 80, $path = '/') */ $transport = new TBufferedTransport($socket); - $protocol = new TBinaryProtocol($transport); + + /** + * Пока наш клиент не умеет общаться по бинарному протоколу, + * инициализируем в зависимости от наличия заголовка + */ + if ( isset($_SERVER['HTTP_X_THRIFT_PROTOCOL']) && $_SERVER['HTTP_X_THRIFT_PROTOCOL'] === self::PROTOCOL_JSON ) + { + $protocol = new TJSONProtocol($transport); + } else { + $protocol = new TBinaryProtocol($transport); + } /** * Инициализируем клиент @@ -136,5 +155,3 @@ public function getClient($host = '127.0.0.1', $port = 80, $path = '/') } } - -