Skip to content

Commit 05659b7

Browse files
committed
Context & header fixes
1 parent 986b604 commit 05659b7

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

src/EventManager.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function __construct($apiKey, SecureNativeOptions $secureNativeOptions)
2525

2626
public function buildEvent(EventOptions $opts)
2727
{
28-
$cookie = $opts->context->clientToken;
28+
$cookie = isset($opts->context->clientToken) ? $opts->context->clientToken : "";
2929
$cookieDecoded = Utils::decrypt($cookie, $this->apiKey);
3030
$clientToken = json_decode($cookieDecoded);
3131

@@ -36,11 +36,11 @@ public function buildEvent(EventOptions $opts)
3636
$cid = $clientToken && $clientToken->cid ? $clientToken->cid : '';
3737
$vid = $clientToken && $clientToken->vid ? $clientToken->vid : '';
3838
$fp = $clientToken && $clientToken->fp ? $clientToken->fp : '';
39-
$ip = $opts->context->ip ? $opts->context->ip : '';
40-
$remoteIp = $opts->context->remoteIp ? $opts->context->remoteIp : '';
41-
$method = $opts->context->method ? $opts->context->method : '';
42-
$url = $opts->context->url ? $opts->context->url : '';
43-
$headers =$opts->context->headers ? $opts->context->headers : null;
39+
$ip = isset($opts->context->ip) ? $opts->context->ip : '';
40+
$remoteIp = isset($opts->context->remoteIp) ? $opts->context->remoteIp : '';
41+
$method = isset($opts->context->method) ? $opts->context->method : '';
42+
$url = isset($opts->context->url) ? $opts->context->url : '';
43+
$headers = isset($opts->context->headers) ? $opts->context->headers : null;
4444

4545
$reqCtx = new RequestContext($cid, $vid, $fp, $ip, $remoteIp, $method, $url, $headers);
4646

src/Utils.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public static function headersFromRequest()
3939
foreach ($_SERVER as $key => $val) {
4040
if (substr($key, 0, 5) == 'HTTP_') {
4141
$name = strtolower(substr($key, 5));
42+
$name = str_replace("_", "-", $name);
4243
$headers[$name] = $val;
4344
}
4445
}

0 commit comments

Comments
 (0)