Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 11 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
DeprecationLoggedHttp | |
0.00% |
0 / 11 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
strStartsWith | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
_setupCurl | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace CirrusSearch\Elastica; |
4 | |
5 | use Elastica\Connection; |
6 | use Elastica\Transport\Http; |
7 | use MediaWiki\Logger\LoggerFactory; |
8 | |
9 | class DeprecationLoggedHttp extends Http { |
10 | |
11 | private $logger; |
12 | |
13 | public function __construct( Connection $connection = null ) { |
14 | parent::__construct( $connection ); |
15 | $this->logger = LoggerFactory::getInstance( 'CirrusSearchDeprecation' ); |
16 | } |
17 | |
18 | private function strStartsWith( $str, $prefix ) { |
19 | // TODO: php 8 use str_starts_with |
20 | return substr( $str, 0, strlen( $prefix ) ) === $prefix; |
21 | } |
22 | |
23 | /** |
24 | * @param resource $curlConnection |
25 | * @return void |
26 | */ |
27 | protected function _setupCurl( $curlConnection ): void { |
28 | parent::_setupCurl( $curlConnection ); |
29 | // @phan-suppress-next-line PhanTypeMismatchArgumentInternal |
30 | curl_setopt( $curlConnection, CURLOPT_HEADERFUNCTION, function ( $curl, $header ) { |
31 | // Elasticsearch sends Warning, but seeing lowercase coming in from curl. Didn't |
32 | // find docs confirming this is standard, do lowercase to have an expectation. |
33 | if ( $this->strStartsWith( strtolower( $header ), 'warning:' ) ) { |
34 | $this->logger->warning( $header, [ |
35 | // A bit awkward, but we want to log a stack trace without |
36 | // being too specific about how that happens. |
37 | 'exception' => new \RuntimeException( $header ), |
38 | ] ); |
39 | } |
40 | return strlen( $header ); |
41 | } ); |
42 | } |
43 | } |