Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions code/BugsnagLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
*
* @package bugsnag-logger
*/
class E7_BugsnagLogger extends Zend_Log_Writer_Abstract {
class E7_BugsnagLogger extends Zend_Log_Writer_Abstract
{

private $bugsnag;

Expand All @@ -26,7 +27,8 @@ class E7_BugsnagLogger extends Zend_Log_Writer_Abstract {
*
* @param Bugsnag_Client $bugsnag
*/
public function __construct(Bugsnag_Client $bugsnag, ReleaseStageInterface $releaseStage = null) {
public function __construct(Bugsnag_Client $bugsnag, ReleaseStageInterface $releaseStage = null)
{
$this->bugsnag = $bugsnag;
if (!$releaseStage) {
$releaseStage = new ReleaseStage();
Expand All @@ -41,7 +43,8 @@ public function __construct(Bugsnag_Client $bugsnag, ReleaseStageInterface $rele
* @param Bugsnag_Client $bugsnag
* @return E7_BugsnagLogger
*/
public static function factory($bugsnag) {
public static function factory($bugsnag)
{
return new E7_BugsnagLogWriter($bugsnag);
}

Expand All @@ -64,13 +67,13 @@ public static function enableWithApiKey($apiKey, ReleaseStageInterface $releaseS
* As Silverstripe internally converts all Exceptions to regular PHP errors
* we will only report PHP errors
*/
public function _write($event) {
public function _write($event)
{
// We only want to log real errors which will come as an array
if (!is_array($event)) {
return;
}
$event = $event['message'];
$this->bugsnag->errorHandler($event['errno'], $event['errstr'], $event['errfile'], $event['errline'], $event['errcontext']);
}

}
}
39 changes: 19 additions & 20 deletions code/ReleaseStage.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
class ReleaseStage implements ReleaseStageInterface
{

const DEVELOPMENT = 'development';
const TESTING = 'testing';
const STAGING = 'staging';
const PRODUCTION = 'production';
const DEVELOPMENT = 'development';
const TESTING = 'testing';
const STAGING = 'staging';
const PRODUCTION = 'production';

protected static $current;
protected static $current;

/**
* Get release stage
Expand All @@ -39,36 +39,36 @@ class ReleaseStage implements ReleaseStageInterface
*/
public function get()
{
// Check if current set
// Check if current set
if (is_null(self::$current)) {
// Get environment variable (if set and valid)
// Get environment variable (if set and valid)
$releaseStage = trim(getenv('RELEASE_STAGE'));
$releaseStage = (in_array($releaseStage, $this->getAll())) ? $releaseStage : null;
$releaseStage = (in_array($releaseStage, $this->getAll())) ? $releaseStage : null;

// If environment variable not set/valid, try to detect staging environment by url or path
if (is_null($releaseStage)) {
// Create paths variable with host name, document root and file path
// Create paths variable with host name, document root and file path
$paths = __FILE__
. (array_key_exists('HTTP_HOST', $_SERVER) ? $_SERVER['HTTP_HOST'] : '')
. (array_key_exists('DOCUMENT_ROOT', $_SERVER) ? $_SERVER['DOCUMENT_ROOT'] : '');

// Now check if paths variable contains "stage" or "staging" keywords
if (strpos($paths, 'stage') !== false || strpos($paths, 'staging') !== false) {
// Set release stage to staging
// Set release stage to staging
$releaseStage = self::STAGING;
} elseif((strpos(__FILE__, '/home') !== false && strpos(__FILE__, 'vhosts') !== false) || file_exists('/home/vagrant')) {
//Check for dev environment that works with cli scripts
} elseif ((strpos(__FILE__, '/home') !== false && strpos(__FILE__, 'vhosts') !== false) || file_exists('/home/vagrant')) {
//Check for dev environment that works with cli scripts
$releaseStage = self::DEVELOPMENT;
}
}

// If environment variable still not set, assume we are in production!
$releaseStage = is_null($releaseStage) ? self::PRODUCTION : $releaseStage;

self::$current = $releaseStage;
self::$current = $releaseStage;
}

return self::$current;
return self::$current;
}

/**
Expand All @@ -78,7 +78,7 @@ public function get()
*/
public function getAll()
{
return array(
return array(
self::DEVELOPMENT => self::DEVELOPMENT,
self::TESTING => self::TESTING,
self::STAGING => self::STAGING,
Expand All @@ -93,7 +93,7 @@ public function getAll()
*/
public function isDevelopment()
{
return $this->get() === self::DEVELOPMENT;
return $this->get() === self::DEVELOPMENT;
}

/**
Expand All @@ -103,7 +103,7 @@ public function isDevelopment()
*/
public function isTesting()
{
return $this->get() === self::TESTING;
return $this->get() === self::TESTING;
}

/**
Expand All @@ -113,7 +113,7 @@ public function isTesting()
*/
public function isStaging()
{
return $this->get() === self::STAGING;
return $this->get() === self::STAGING;
}

/**
Expand All @@ -123,7 +123,6 @@ public function isStaging()
*/
public function isProduction()
{
return $this->get() === self::PRODUCTION;
return $this->get() === self::PRODUCTION;
}

}
2 changes: 1 addition & 1 deletion code/ReleaseStageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ interface ReleaseStageInterface
* @return string Textual description of the current release stage
*/
public function get();
}
}