From d5b738c3a2f37e25adb9d0e4e17867105565e410 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Mon, 20 May 2024 16:53:10 +0000 Subject: [PATCH] chore: update logging provider constructors --- src/Logger/Adapter/AppSignal.php | 20 +++++++-------- src/Logger/Adapter/LogOwl.php | 32 ++++++++++++------------ src/Logger/Adapter/Raygun.php | 20 +++++++-------- src/Logger/Adapter/Sentry.php | 42 ++++++-------------------------- 4 files changed, 43 insertions(+), 71 deletions(-) diff --git a/src/Logger/Adapter/AppSignal.php b/src/Logger/Adapter/AppSignal.php index df755ea..7d5a629 100644 --- a/src/Logger/Adapter/AppSignal.php +++ b/src/Logger/Adapter/AppSignal.php @@ -17,6 +17,16 @@ class AppSignal extends Adapter */ protected string $apiKey; + /** + * AppSignal constructor. + * + * @param string $key + */ + public function __construct(string $key) + { + $this->apiKey = $key; + } + /** * Return unique adapter name * @@ -127,16 +137,6 @@ public function push(Log $log): int return $response; } - /** - * AppSignal constructor. - * - * @param string $configKey - */ - public function __construct(string $configKey) - { - $this->apiKey = $configKey; - } - public function getSupportedTypes(): array { return [ diff --git a/src/Logger/Adapter/LogOwl.php b/src/Logger/Adapter/LogOwl.php index dc362a4..920d5da 100644 --- a/src/Logger/Adapter/LogOwl.php +++ b/src/Logger/Adapter/LogOwl.php @@ -24,6 +24,22 @@ class LogOwl extends Adapter */ protected string $logOwlHost; + /** + * LogOwl constructor. + * + * @param string $ticket + * @param string $host + */ + public function __construct(string $ticket, string $host) + { + $this->ticket = $ticket; + $this->logOwlHost = 'https://api.logowl.io/logging/'; + + if (!empty($host)) { + $this->logOwlHost = $host; + } + } + /** * Return unique adapter name * @@ -140,22 +156,6 @@ public function push(Log $log): int return $response; } - /** - * LogOwl constructor. - * - * @param string $configKey - */ - public function __construct(string $configKey) - { - $configChunks = \explode(';', $configKey); - $this->ticket = $configChunks[0]; - $this->logOwlHost = 'https://api.logowl.io/logging/'; - - if (count($configChunks) > 1 && ! empty($configChunks[1])) { - $this->logOwlHost = $configChunks[1]; - } - } - public function getSupportedTypes(): array { return [ diff --git a/src/Logger/Adapter/Raygun.php b/src/Logger/Adapter/Raygun.php index 2f479ab..833a9c0 100644 --- a/src/Logger/Adapter/Raygun.php +++ b/src/Logger/Adapter/Raygun.php @@ -17,6 +17,16 @@ class Raygun extends Adapter */ protected string $apiKey; + /** + * Raygun constructor. + * + * @param string $key + */ + public function __construct(string $key) + { + $this->apiKey = $key; + } + /** * Return unique adapter name * @@ -112,16 +122,6 @@ public function push(Log $log): int return $response; } - /** - * Raygun constructor. - * - * @param string $configKey - */ - public function __construct(string $configKey) - { - $this->apiKey = $configKey; - } - public function getSupportedTypes(): array { return [ diff --git a/src/Logger/Adapter/Sentry.php b/src/Logger/Adapter/Sentry.php index 929e7ca..06b775c 100644 --- a/src/Logger/Adapter/Sentry.php +++ b/src/Logger/Adapter/Sentry.php @@ -26,47 +26,19 @@ class Sentry extends Adapter * @var string (optional, the host where Sentry is reachable, in case of self-hosted Sentry could * look like 'https://sentry.mycompany.com'. defaults to 'https://sentry.io') */ - protected string $sentryHost; + protected string $sentryHost = 'https://sentry.io'; /** * Sentry constructor. * - * @param string $dsn + * @param string $projectId + * @param string $key + * @param string $host */ - public function __construct(string $dsn) + public function __construct(string $projectId, string $key, string $host) { - $parsedDsn = parse_url($dsn); - - if ($parsedDsn === false) { - throw new \Exception("The '$dsn' DSN is invalid."); - } - - $host = $parsedDsn['host'] ?? ''; - $path = $parsedDsn['path'] ?? ''; - $user = $parsedDsn['user'] ?? ''; - $scheme = $parsedDsn['scheme'] ?? ''; - - if (empty($scheme) || empty($host) || empty($path) || empty($user)) { - throw new \Exception("The '$dsn' DSN must contain a scheme, a host, a user and a path component."); - } - - if (! \in_array($scheme, ['http', 'https'], true)) { - throw new \Exception("The scheme of the $dsn DSN must be either 'http' or 'https'"); - } - - $segmentPaths = explode('/', $path); - $projectId = array_pop($segmentPaths); - - $url = $scheme.'://'.$host; - $port = $parsedDsn['port'] ?? ($scheme === 'http' ? 80 : 443); - if (($scheme === 'http' && $port !== 80) || - ($scheme === 'https' && $port !== 443) - ) { - $url .= ':'.$port; - } - - $this->sentryHost = $url; - $this->sentryKey = $user; + $this->sentryHost = $host; + $this->sentryKey = $key; $this->projectId = $projectId; }