diff --git a/Client.php b/Client.php index 8c9be1a..119f420 100644 --- a/Client.php +++ b/Client.php @@ -4,8 +4,6 @@ namespace FOS\ElasticaBundle; use Elastica\Client as ElasticaClient; use Elastica\Request; -use Elastica\Transport\Http; -use Elastica\Transport\Https; /** * @author Gordon Franke @@ -21,14 +19,14 @@ class Client extends ElasticaClient $time = microtime(true) - $start; $connection = $this->getLastRequest()->getConnection(); - $transport = $connection->getTransportObject(); - $full_host = null; - if ($transport instanceof Http || $transport instanceof Https) { - $full_host = $connection->getTransport().'://'.$connection->getHost().':'.$connection->getPort(); - } + $connection_array = array( + 'host' => $connection->getHost(), + 'port' => $connection->getPort(), + 'transport' => $connection->getTransport(), + ); - $this->_logger->logQuery($path, $method, $data, $time, $full_host); + $this->_logger->logQuery($path, $method, $data, $time, $connection_array); } return $response; diff --git a/Logger/ElasticaLogger.php b/Logger/ElasticaLogger.php index 2d8d0ae..bf7694e 100644 --- a/Logger/ElasticaLogger.php +++ b/Logger/ElasticaLogger.php @@ -38,9 +38,9 @@ class ElasticaLogger implements LoggerInterface * @param string $method Rest method to use (GET, POST, DELETE, PUT) * @param array $data arguments * @param float $time execution time - * @param string $full_host host and port of the query + * @param array $connection host, port and transport of the query */ - public function logQuery($path, $method, $data, $time, $full_host = null) + public function logQuery($path, $method, $data, $time, $connection = array()) { if ($this->debug) { $this->queries[] = array( @@ -48,7 +48,7 @@ class ElasticaLogger implements LoggerInterface 'method' => $method, 'data' => $data, 'executionMS' => $time, - 'full_host' => $full_host + 'connection' => $connection ); } diff --git a/Resources/views/Collector/elastica.html.twig b/Resources/views/Collector/elastica.html.twig index 8b27376..5da6048 100644 --- a/Resources/views/Collector/elastica.html.twig +++ b/Resources/views/Collector/elastica.html.twig @@ -44,7 +44,7 @@ {% for key, query in collector.queries %}
  • Path: {{ query.path }}
    - Method: {{ query.method }} + Method: {{ query.method }} ({{ query.connection.transport }} on {{ query.connection.host }}:{{ query.connection.port }})
    {{ query.data|json_encode }}
    @@ -52,7 +52,7 @@ Time: {{ '%0.2f'|format(query.executionMS * 1000) }} ms - {% if query.full_host %} + {% if query.connection.transport in ['Http', 'Https'] %}{# cURL support only HTTP #} + - @@ -60,7 +60,7 @@ {% endif %}
  • diff --git a/Tests/Logger/ElasticaLoggerTest.php b/Tests/Logger/ElasticaLoggerTest.php index 73ba4ac..18eb44b 100644 --- a/Tests/Logger/ElasticaLoggerTest.php +++ b/Tests/Logger/ElasticaLoggerTest.php @@ -35,17 +35,17 @@ class ElasticaLoggerTest extends \PHPUnit_Framework_TestCase $method = 'testMethod'; $data = array('data'); $time = 12; - $full_host = 'http://example.com:9200'; + $connection = array('host' => 'localhost', 'port' => '8999', 'transport' => 'https'); $expected = array( 'path' => $path, 'method' => $method, 'data' => $data, 'executionMS' => $time, - 'full_host' => $full_host, + 'connection' => $connection, ); - $elasticaLogger->logQuery($path, $method, $data, $time, $full_host); + $elasticaLogger->logQuery($path, $method, $data, $time, $connection); $returnedQueries = $elasticaLogger->getQueries(); $this->assertEquals($expected, $returnedQueries[0]); }