Skip to content

Commit

Permalink
Merge pull request #2 from LiveTex/binary_or_json
Browse files Browse the repository at this point in the history
Инициализация бинарного или json протокола.
  • Loading branch information
ikoolik committed Mar 19, 2015
2 parents 7774b76 + 9e8100d commit 58eeca4
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/Platform/Endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,6 +16,8 @@ class Endpoint
{
protected $config;
protected $transport = null;

const PROTOCOL_JSON = 'JSON';

public function __construct(EndpointConfig $config)
{
Expand Down Expand Up @@ -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();

/**
Expand Down Expand Up @@ -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);
}

/**
* Инициализируем клиент
Expand All @@ -136,5 +155,3 @@ public function getClient($host = '127.0.0.1', $port = 80, $path = '/')
}

}


0 comments on commit 58eeca4

Please sign in to comment.