Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 14 |
DeprecationLoggedHttp | |
0.00% |
0 / 1 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 14 |
__construct | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
strStartsWith | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
_setupCurl | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 9 |
<?php | |
namespace CirrusSearch\Elastica; | |
use Elastica\Connection; | |
use Elastica\Transport\Http; | |
use MediaWiki\Logger\LoggerFactory; | |
class DeprecationLoggedHttp extends Http { | |
private $logger; | |
public function __construct( Connection $connection = null ) { | |
parent::__construct( $connection ); | |
$this->logger = LoggerFactory::getInstance( 'CirrusSearchDeprecation' ); | |
} | |
private function strStartsWith( $str, $prefix ) { | |
// TODO: php 8 use str_starts_with | |
return substr( $str, 0, strlen( $prefix ) ) === $prefix; | |
} | |
protected function _setupCurl( $curlConnection ) { | |
parent::_setupCurl( $curlConnection ); | |
curl_setopt( $curlConnection, CURLOPT_HEADERFUNCTION, function ( $curl, $header ) { | |
// Elasticsearch sends Warning, but seeing lowercase coming in from curl. Didn't | |
// find docs confirming this is standard, do lowercase to have an expectation. | |
if ( $this->strStartsWith( strtolower( $header ), 'warning:' ) ) { | |
$this->logger->warning( $header, [ | |
// A bit awkward, but we want to log a stack trace without | |
// being too specific about how that happens. | |
'exception' => new \RuntimeException( $header ), | |
] ); | |
} | |
return strlen( $header ); | |
} ); | |
} | |
} |