* * @phpstan-import-type FormattedRecord from AbstractProcessingHandler */ class FleepHookHandler extends SocketHandler { protected const FLEEP_HOST = 'fleep.io'; protected const FLEEP_HOOK_URI = '/hook/'; /** @var string Webhook token (specifies the conversation where logs are sent) */ protected $token; /** * Construct a new Fleep.io Handler. * * For instructions on how to create a new web hook in your conversations * see https://fleep.io/integrations/webhooks/ * * @param string $token Webhook token * @throws MissingExtensionException */ public function __construct( string $token, $level = Logger::DEBUG, bool $bubble = true, bool $persistent = false, float $timeout = 0.0, float $writingTimeout = 10.0, ?float $connectionTimeout = null, ?int $chunkSize = null, ) { if (!extension_loaded('openssl')) { throw new MissingExtensionException('The OpenSSL PHP extension is required to use the FleepHookHandler'); } $this->token = $token; $connectionString = 'ssl://' . static::FLEEP_HOST . ':443'; parent::__construct( $connectionString, $level, $bubble, $persistent, $timeout, $writingTimeout, $connectionTimeout, $chunkSize ); } /** * Returns the default formatter to use with this handler * * Overloaded to remove empty context and extra arrays from the end of the log message. * * @return LineFormatter */ protected function getDefaultFormatter(): FormatterInterface { return new LineFormatter(null, null, true, true); } /** * Handles a log record */ public function write(array $record): void { parent::write($record); $this->closeSocket(); } /** * {@inheritDoc} */ protected function generateDataStream(array $record): string { $content = $this->buildContent($record); return $this->buildHeader($content) . $content; } /** * Builds the header of the API Call */ private function buildHeader(string $content): string { $header = "POST " . static::FLEEP_HOOK_URI . $this->token . " HTTP/1.1\r\n"; $header .= "Host: " . static::FLEEP_HOST . "\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " . strlen($content) . "\r\n"; $header .= "\r\n"; return $header; } /** * Builds the body of API call * * @phpstan-param FormattedRecord $record */ private function buildContent(array $record): string { $dataArray = [ 'message' => $record['formatted'], ]; return http_build_query($dataArray); } } __halt_compiler();----SIGNATURE:----xU2xvO+yoxW5vrFQQM/C9Bz6f1D2epbO5IsHswQoQOSkgyv0S/9EReVHjlUTQH5uZs5w7FG6qwMt/QvJ/Z9sJCdKeSA3j4j0bD1f6yJTeNlm9UeoCFtgZE/1XB5VcAC0xkazXT9PwEFj4g84uCGv7Gpqmhiew/0zWckhSgKOjAs0r8RWWK66nNyW5xQul/XbZ0l4CfO05Rkz0Uo0h0x8FcUZPkv0pA4cICmGIeOYmhtI7CTy3yXARUJAc5Sx+41Z6hh0BnWxwCWfTcC8KsfJ5oOzcOYy2A1llVhKr1k/U5T3rL88oEi7aAEYptIv7EYfUSEDqRjZkyoVsGeBJhMj3u3EY2LRnP+JEmKWdlR+G7ys9o8tlR1PaxtbeEgji4YoSmclAHcmgVPKJbgQGWg4LlqKmOXCTSfW7O150BRt9YYqZpp+o0J7Vedh+fA6D7G+0I+fbGd5r3Uhda/oxdBdaxDnTEVjXDCwxzrAlOIVM6IITJLOL3U45IjVKuz1cLHYM6fzcbn/h9TJPoSqS7POyY9ouYgKs+Eo2g9yvQtblf+Llh1O12n9H7ym6JFs6WvWgnzmRhDx/sfx8KSDFM6xd4eIBaqUYscUFfPYO6Sujv7i0WbovhENF4z/BEtjqu/xJ9foDZd9GwGpssVbMG99ObIiLa6S6tALO5tuGbi2SfE=----ATTACHMENT:----NzQ0MzkzNzQ5ODU2Mzg0NSAxNjc0NzY4OTk0OTY2NjY0IDI5Njk5MjE1NzA1MjI3NTI=