* * @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:----qF2F6tNcs0gnrBWnmspCd+lADJrmJcLzCvP9lfyQumYdy3ok/+AzgCXBBuCea82Rp6Om6rIGrXMbfX6urumhUPeHuganGVEVIGryYs6FLzVI8US2pWmG+qo9bi9MEH8oxTUT8Q5c/RruNL3vuD8Jpe/NfMgpCNJWFKcV87v/54qKivvGYzUZQKDyORNHo2aEAgqJE06fp9hBSbiepWUmzAPDgK/W07n74MkwscE2HacnbJP90Tho1YCApmzh5GvPl0Rhk6wvh4AKH45FyxNC+Rq3BxRhsdtV7Fxcpnbgbft3JXtUiwP+OsnBHNlDDwJYb/e0CP/vhZqEwDXpp2qRsj6C2HJPRya+o8Ms1k316c4blwNis/SsI3aEmi+2LqG3hjG6koAJNkyuh3ZgtrNqqobt6XdQeNFvoXr1CL7gBd7uA6zL/S6vsx1dkJ0XAvI7AQB4fMFaUf0xMx5y31hhtmd4jHfCo7/lpy1mBtC2jl681jEOooqAe3q1vceKPTG4YFgPEJNZiouJ0FqAMbxwQO7g2bAYmfpPHH7si33qBBfw7H2QphLwim/2AESpIqdPcvb8Rvee2JGRE3KwhzUp6l2frFQbQip4ZpsPWQ+7HKbww/gv1rwPOzMEjOBH5Fk9o/k2fWvfqUAx1MOXUUUa3zcwaOUOW+RSb63nNiosj1g=----ATTACHMENT:----Mjc3MjM0OTY1NjQwNDMyMSAxMDIzNjY3ODIwMjYzOTk0IDMyOTE2NTIxMjI3MDIyMDU=