Skip to content

Commit

Permalink
Merge pull request #92 from MindscapeHQ/1.8.0-release
Browse files Browse the repository at this point in the history
1.8.0 Release
  • Loading branch information
BenjaminHarding authored Mar 6, 2017
2 parents 4cce3e7 + adfb9a7 commit eb56e85
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 12 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,21 @@ $client->setFilterParams(array(

Note that when any filters are defined, the Raygun error will no longer contain the raw HTTP data, since there's no effective way to filter it.

### Updating Cookie options

Cookies are used for the user tracking functionality of the Raygun4Php provider. In version 1.8 of the provider, the options passed to the `setcookie` method can now be customized to your needs.

```php
$client = new \Raygun4php\RaygunClient("apiKey");
$client->SetCookieOptions(array(
'expire' => 2592000, // 30 * 24 * 60 * 60
'path' => '/',
'domain' => '',
'secure' => false,
'httponly' => false
));
```

## Troubleshooting

As above, enable debug mode by instantiating the client with
Expand All @@ -275,9 +290,10 @@ If, when running a PHP script from the command line on *nix operating systems, y

## Changelog

- 1.8.0: Bugfix with multiple cookies being set. Cookie options can be set via the setCookieOptions method
- 1.7.1: Fixed illegal string offset
- 1.7.0: Added custom error grouping
- 1.6.1: Assign ClassName as exceptionClass
- 1.6.1: Assign ClassName as exceptionClass
- 1.6.0: Added HTTP proxy support, support X-Forwarded-For, null server var guards
- 1.5.3: Unify property casing (internal change)
- 1.5.2: Prevent error when query_string isn't present in $_SERVER
Expand Down
54 changes: 44 additions & 10 deletions src/Raygun4php/RaygunClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ class RaygunClient

protected $groupingKeyCallback;

protected $cookieOptions = array(
'use' => true,
'expire' => 2592000, // 30 * 24 * 60 * 60
'path' => '/',
'domain' => '',
'secure' => false,
'httponly' => false
);

/**
* @var Array Parameter names to filter out of logged form data. Case insensitive.
* Accepts regular expressions when the name starts with a forward slash.
Expand Down Expand Up @@ -141,8 +150,6 @@ public function SetVersion($version)
*/
public function SetUser($user = null, $firstName = null, $fullName = null, $email = null, $isAnonymous = null, $uuid = null)
{
$timestamp = time() + 60 * 60 * 24 * 30;

$this->firstName = $this->StoreOrRetrieveUserCookie('rgfirstname', $firstName);
$this->fullName = $this->StoreOrRetrieveUserCookie('rgfullname', $fullName);
$this->email = $this->StoreOrRetrieveUserCookie('rgemail', $email);
Expand All @@ -156,8 +163,8 @@ public function SetUser($user = null, $firstName = null, $fullName = null, $emai

if (php_sapi_name() != 'cli' && !headers_sent())
{
setcookie('rguserid', $user, $timestamp);
setcookie('rguuid', 'false', $timestamp);
$this->setCookie('rguserid', $user);
$this->setCookie('rguuid', 'false');
}
}
else
Expand All @@ -168,8 +175,8 @@ public function SetUser($user = null, $firstName = null, $fullName = null, $emai

if (php_sapi_name() != 'cli' && !headers_sent())
{
setcookie('rguserid', $this->user, $timestamp);
setcookie('rguuid', 'true', $timestamp);
$this->setCookie('rguserid', $this->user);
$this->setCookie('rguuid', 'true');
}
}
else if (array_key_exists('rguserid', $_COOKIE))
Expand All @@ -196,13 +203,11 @@ public function SetGroupingKey($callback) {

private function StoreOrRetrieveUserCookie($key, $value)
{
$timestamp = time() + 60 * 60 * 24 * 30;

if (is_string($value))
{
if (php_sapi_name() != 'cli' && !headers_sent())
{
setcookie($key, $value, $timestamp);
$this->setCookie($key, $value);
}

return $value;
Expand All @@ -213,7 +218,7 @@ private function StoreOrRetrieveUserCookie($key, $value)
{
if ($_COOKIE[$key] != $value && php_sapi_name() != 'cli' && !headers_sent())
{
setcookie($key, $value, $timestamp);
$this->setCookie($key, $value);
}
return $_COOKIE[$key];
}
Expand All @@ -222,6 +227,19 @@ private function StoreOrRetrieveUserCookie($key, $value)
return null;
}

/**
* @param string $name
* @param string $value
*/
protected function setCookie($name, $value)
{
$options = $this->cookieOptions;

if ($options['use'] === true) {
setcookie($name, $value, time() + $options['expire'], $options['path'], $options['domain'], $options['secure'], $options['httponly']);
}
}

/*
* Sets a string array of tags relating to the message,
* used for identification. These will be transmitted along with messages that
Expand Down Expand Up @@ -484,6 +502,22 @@ function setProxy($proxy) {
return $this;
}

/**
* Sets the given cookie options
*
* Existing values will be overridden. Values that are missing from the array being set will keep their current
* values.
*
* The key names match the argument names on setcookie() (e.g. 'expire' or 'path'). Pass the default value according
* to PHP's setcookie() function to ignore that parameter.
*
* @param array<string,mixed> $options
*/
public function SetCookieOptions($options)
{
$this->cookieOptions = array_merge($this->cookieOptions, $options);
}

/**
* @return String
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Raygun4php/RaygunClientMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class RaygunClientMessage
public function __construct()
{
$this->Name = "Raygun4php";
$this->Version = "1.7.1";
$this->Version = "1.8.0";
$this->ClientUrl = "https://github.com/MindscapeHQ/raygun4php";
}
}
Expand Down

0 comments on commit eb56e85

Please sign in to comment.