Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/ElasticSearch/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,4 +274,16 @@ protected static function parseDsn($dsn) {
}
return compact('protocol', 'servers', 'index', 'type');
}

/**
* Add a handler called every time a request is made to ElasticSearch
*
* @param callable $cb
* @return void
*/
public function addOnCallHandler($cb)
{
$this->transport->onCall[] = $cb;
}

}
7 changes: 7 additions & 0 deletions src/ElasticSearch/Transport/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ abstract class Base {
*/
protected $type;

/**
* called on each request
* @var array f(url, method, payload, return)
*/
public $onCall;


/**
* Default constructor, just set host and port
* @param string $host
Expand Down
7 changes: 7 additions & 0 deletions src/ElasticSearch/Transport/HTTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,13 @@ protected function call($url, $method="GET", $payload=false) {
throw $exception;
}

// callback
if ($this->onCall) {
foreach ($this->onCall as $cb) {
call_user_func($cb, $url, $method, $payload, $data);
}
}

return $data;
}
}