FOSElasticaBundle/Client.php

38 lines
808 B
PHP
Raw Normal View History

2011-10-04 17:01:38 +02:00
<?php
2011-10-04 17:26:14 +02:00
namespace FOS\ElasticaBundle;
2011-10-04 17:01:38 +02:00
use Elastica\Client as ElasticaClient;
2013-05-06 10:32:50 +02:00
use Elastica\Request;
use FOS\ElasticaBundle\Logger\ElasticaLogger;
2011-10-04 17:01:38 +02:00
/**
* @author Gordon Franke <info@nevalon.de>
*/
class Client extends ElasticaClient
2011-10-04 17:01:38 +02:00
{
/**
* @var ElasticaLogger
*/
2011-10-04 17:26:14 +02:00
protected $logger;
2011-10-04 17:53:28 +02:00
public function setLogger(ElasticaLogger $logger)
2011-10-04 17:01:38 +02:00
{
$this->logger = $logger;
}
public function request($path, $method = Request::GET, $data = array(), array $query = array())
2011-10-04 17:26:14 +02:00
{
$start = microtime(true);
2012-05-02 00:06:28 +02:00
$response = parent::request($path, $method, $data, $query);
2011-10-04 17:26:14 +02:00
if (null !== $this->logger) {
$time = microtime(true) - $start;
$this->logger->logQuery($path, $method, $data, $time);
2011-10-04 17:26:14 +02:00
}
2011-10-04 17:01:38 +02:00
return $response;
2011-10-04 17:01:38 +02:00
}
}