Skip to content

Commit

Permalink
chore: update logging provider constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
christyjacob4 committed May 20, 2024
1 parent c6dfdb6 commit d5b738c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 71 deletions.
20 changes: 10 additions & 10 deletions src/Logger/Adapter/AppSignal.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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 [
Expand Down
32 changes: 16 additions & 16 deletions src/Logger/Adapter/LogOwl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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 [
Expand Down
20 changes: 10 additions & 10 deletions src/Logger/Adapter/Raygun.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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 [
Expand Down
42 changes: 7 additions & 35 deletions src/Logger/Adapter/Sentry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit d5b738c

Please sign in to comment.