@@ -25,43 +25,43 @@ discard block |
||
| 25 | 25 | /** |
| 26 | 26 | * The http client instance. |
| 27 | 27 | * |
| 28 | - * @var \Http\Client\HttpClient |
|
| 29 | - */ |
|
| 30 | - protected $client; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * The message factory instance. |
|
| 34 | - * |
|
| 35 | - * @var \Http\Message\MessageFactory |
|
| 36 | - */ |
|
| 37 | - protected $messageFactory; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * The options array. |
|
| 41 | - * |
|
| 42 | - * @var array |
|
| 43 | - */ |
|
| 44 | - protected $options = [ |
|
| 45 | - 'uri' => null, |
|
| 46 | - 'method' => 'GET', |
|
| 47 | - 'headers' => [ |
|
| 48 | - 'Content-Type' => 'application/json' |
|
| 49 | - ], |
|
| 50 | - 'protocolVersion' => '1.1' |
|
| 51 | - ]; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Create a new monolog http client handler instance. |
|
| 55 | - * |
|
| 56 | - * @param array $options The array of options consisting of the uri, method, headers and protocol |
|
| 57 | - * version. |
|
| 58 | - * @param HttpClient|null $client An instance of a psr-7 http client implementation or null when the |
|
| 59 | - * HttpClientDiscovery should be used to find an instance. |
|
| 60 | - * @param MessageFactory|null $factory An instance of a psr-7 message factory implementation or null when |
|
| 61 | - * the MessageFactoryDiscovery should be used to find an instance. |
|
| 62 | - * @param int $level The minimum logging level at which this handler will be triggered. |
|
| 63 | - * @param boolean $bubble Whether the messages that are handled can bubble up the stack or not. |
|
| 64 | - */ |
|
| 28 | + * @var \Http\Client\HttpClient |
|
| 29 | + */ |
|
| 30 | + protected $client; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * The message factory instance. |
|
| 34 | + * |
|
| 35 | + * @var \Http\Message\MessageFactory |
|
| 36 | + */ |
|
| 37 | + protected $messageFactory; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * The options array. |
|
| 41 | + * |
|
| 42 | + * @var array |
|
| 43 | + */ |
|
| 44 | + protected $options = [ |
|
| 45 | + 'uri' => null, |
|
| 46 | + 'method' => 'GET', |
|
| 47 | + 'headers' => [ |
|
| 48 | + 'Content-Type' => 'application/json' |
|
| 49 | + ], |
|
| 50 | + 'protocolVersion' => '1.1' |
|
| 51 | + ]; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Create a new monolog http client handler instance. |
|
| 55 | + * |
|
| 56 | + * @param array $options The array of options consisting of the uri, method, headers and protocol |
|
| 57 | + * version. |
|
| 58 | + * @param HttpClient|null $client An instance of a psr-7 http client implementation or null when the |
|
| 59 | + * HttpClientDiscovery should be used to find an instance. |
|
| 60 | + * @param MessageFactory|null $factory An instance of a psr-7 message factory implementation or null when |
|
| 61 | + * the MessageFactoryDiscovery should be used to find an instance. |
|
| 62 | + * @param int $level The minimum logging level at which this handler will be triggered. |
|
| 63 | + * @param boolean $bubble Whether the messages that are handled can bubble up the stack or not. |
|
| 64 | + */ |
|
| 65 | 65 | public function __construct( |
| 66 | 66 | array $options = [], |
| 67 | 67 | HttpClient $client = null, |
@@ -191,78 +191,78 @@ discard block |
||
| 191 | 191 | public function handleBatch(array $records) |
| 192 | 192 | { |
| 193 | 193 | foreach ($records as $key => $record) { |
| 194 | - if ($this->isHandling($record)) { |
|
| 195 | - $record = $this->processRecord($record); |
|
| 196 | - $records['records'][] = $record; |
|
| 197 | - } |
|
| 194 | + if ($this->isHandling($record)) { |
|
| 195 | + $record = $this->processRecord($record); |
|
| 196 | + $records['records'][] = $record; |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | 199 | unset($records[$key]); |
| 200 | - } |
|
| 200 | + } |
|
| 201 | 201 | |
| 202 | - $records['formatted'] = $this->getFormatter()->formatBatch($records['records'] ?? []); |
|
| 202 | + $records['formatted'] = $this->getFormatter()->formatBatch($records['records'] ?? []); |
|
| 203 | 203 | |
| 204 | - $this->write($records); |
|
| 204 | + $this->write($records); |
|
| 205 | 205 | |
| 206 | - return false === $this->bubble; |
|
| 206 | + return false === $this->bubble; |
|
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | /** |
| 210 | - * Gets the default formatter. |
|
| 211 | - * |
|
| 212 | - * @return \Monolog\Formatter\JsonFormatter |
|
| 213 | - */ |
|
| 214 | - protected function getDefaultFormatter() : FormatterInterface |
|
| 215 | - { |
|
| 216 | - return new JsonFormatter(); |
|
| 217 | - } |
|
| 210 | + * Gets the default formatter. |
|
| 211 | + * |
|
| 212 | + * @return \Monolog\Formatter\JsonFormatter |
|
| 213 | + */ |
|
| 214 | + protected function getDefaultFormatter() : FormatterInterface |
|
| 215 | + { |
|
| 216 | + return new JsonFormatter(); |
|
| 217 | + } |
|
| 218 | 218 | |
| 219 | 219 | /** |
| 220 | - * Returns the HTTP adapter. |
|
| 221 | - * |
|
| 222 | - * @return \Http\Client\HttpClient |
|
| 223 | - */ |
|
| 224 | - protected function getHttpClient(): HttpClient |
|
| 225 | - { |
|
| 226 | - return $this->client; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * Returns the message factory. |
|
| 231 | - * |
|
| 232 | - * @return \Http\Message\MessageFactory |
|
| 233 | - */ |
|
| 234 | - protected function getMessageFactory(): MessageFactory |
|
| 235 | - { |
|
| 236 | - return $this->messageFactory; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - /** |
|
| 240 | - * Writes the record. |
|
| 241 | - * |
|
| 242 | - * @param array $record |
|
| 243 | - * @return void |
|
| 244 | - */ |
|
| 245 | - protected function write(array $record) |
|
| 246 | - { |
|
| 247 | - $uri = $this->getUri(); |
|
| 248 | - |
|
| 249 | - if (empty($uri)) { |
|
| 250 | - return; |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - $request = $this->getMessageFactory()->createRequest( |
|
| 254 | - $this->getMethod(), |
|
| 255 | - $this->getUri(), |
|
| 256 | - $this->getHeaders(), |
|
| 257 | - $record['formatted'], |
|
| 258 | - $this->getProtocolVersion() |
|
| 259 | - ); |
|
| 260 | - |
|
| 261 | - try { |
|
| 262 | - $this->getHttpClient()->sendRequest($request); |
|
| 263 | - } catch (\Exception $e) { |
|
| 264 | - // QUESTION(msschl): How to handle the thrown exceptions??? |
|
| 265 | - return; |
|
| 266 | - } |
|
| 267 | - } |
|
| 220 | + * Returns the HTTP adapter. |
|
| 221 | + * |
|
| 222 | + * @return \Http\Client\HttpClient |
|
| 223 | + */ |
|
| 224 | + protected function getHttpClient(): HttpClient |
|
| 225 | + { |
|
| 226 | + return $this->client; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * Returns the message factory. |
|
| 231 | + * |
|
| 232 | + * @return \Http\Message\MessageFactory |
|
| 233 | + */ |
|
| 234 | + protected function getMessageFactory(): MessageFactory |
|
| 235 | + { |
|
| 236 | + return $this->messageFactory; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + /** |
|
| 240 | + * Writes the record. |
|
| 241 | + * |
|
| 242 | + * @param array $record |
|
| 243 | + * @return void |
|
| 244 | + */ |
|
| 245 | + protected function write(array $record) |
|
| 246 | + { |
|
| 247 | + $uri = $this->getUri(); |
|
| 248 | + |
|
| 249 | + if (empty($uri)) { |
|
| 250 | + return; |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + $request = $this->getMessageFactory()->createRequest( |
|
| 254 | + $this->getMethod(), |
|
| 255 | + $this->getUri(), |
|
| 256 | + $this->getHeaders(), |
|
| 257 | + $record['formatted'], |
|
| 258 | + $this->getProtocolVersion() |
|
| 259 | + ); |
|
| 260 | + |
|
| 261 | + try { |
|
| 262 | + $this->getHttpClient()->sendRequest($request); |
|
| 263 | + } catch (\Exception $e) { |
|
| 264 | + // QUESTION(msschl): How to handle the thrown exceptions??? |
|
| 265 | + return; |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | 268 | } |
| 269 | 269 | \ No newline at end of file |