Skip to content

Commit

Permalink
Initialize fork of a library and changes for compatibility with php52.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea Giannantonio committed Mar 23, 2017
1 parent 7b541b0 commit cbdb640
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 37 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# http:https://editorconfig.org
root = true

[*]
indent_style = space
indent_size = 4
tab_width = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 120

[*.md]
trim_trailing_whitespace = false
5 changes: 5 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
1.8.0
-----

- Changes for compatibility with php5.2

1.7.0
-----

Expand Down
19 changes: 9 additions & 10 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
sentry-php
==========
immobiliare/sentry-php
======================

.. image:: https://secure.travis-ci.org/getsentry/sentry-php.png?branch=master
:target: http:https://travis-ci.org/getsentry/sentry-php


The official PHP SDK for `Sentry <https://getsentry.com/>`_.
This project is a fork of official PHP SDK v1.7.0 for `Sentry <https://getsentry.com/>`_ to work even with php5.2.

.. code-block:: php
// Instantiate a new client with a compatible DSN and install built-in
// handlers
$client = (new Raven_Client('http:https://public:[email protected]/1'))->install();
$sentryClient = new Raven_Client('https://e9ebbd88548a441288393c457ec90441:[email protected]/3235');
$sentryClient->install();
// Capture an exception
$event_id = $client->captureException($ex);
$event_id = $sentryClient->captureException($ex);
// Give the user feedback
echo "Sorry, there was an error!";
echo "Your reference ID is " . $event_id;
For more information, see our `documentation <https://docs.getsentry.com/hosted/clients/php/>`_.
For more information, see the `documentation <https://docs.getsentry.com/hosted/clients/php/>`_.


Contributing
Expand All @@ -44,7 +45,5 @@ Resources
---------

* `Documentation <https://docs.getsentry.com/hosted/clients/php/>`_
* `Bug Tracker <http:https://github.com/getsentry/sentry-php/issues>`_
* `Code <http:https://github.com/getsentry/sentry-php>`_
* `Mailing List <https://groups.google.com/group/getsentry>`_
* `IRC <irc:https://irc.freenode.net/sentry>`_ (irc.freenode.net, #sentry)
* `Bug Tracker <http:https://github.com/immobiliare/sentry-php/issues>`_
* `Code <http:https://github.com/immobiliare/sentry-php>`_
12 changes: 8 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
{
"name": "sentry/sentry",
"name": "immobiliare/sentry-php",
"type": "library",
"description": "A PHP client for Sentry (http:https://getsentry.com)",
"keywords": ["log", "logging"],
"homepage": "http:https://getsentry.com",
"description": "Fork of a PHP client for Sentry (http:https://getsentry.com) that work also with php5.2",
"keywords": ["log", "logging", "sentry", "sentry-php", "php52", "php 5.2"],
"homepage": "https:https://github.com/immobiliare/sentry-php",
"license": "BSD-3-Clause",
"authors": [
{
"name": "David Cramer",
"email": "[email protected]"
},
{
"name": "ImmobiliareLabs",
"email": "[email protected]"
}
],
"require-dev": {
Expand Down
8 changes: 5 additions & 3 deletions examples/vanilla/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@

function setupSentry()
{
(new \Raven_Client(SENTRY_DSN))
->setAppPath(__DIR__)
$sentryClient = new Raven_Client(SENTRY_DSN);
$__DIR__ = version_compare(PHP_VERSION, '5.3.0', '>=') ? __DIR__ : dirname(__FILE__);

$sentryClient->setAppPath($__DIR__)
->setRelease(Raven_Client::VERSION)
->setPrefixes(array(__DIR__))
->setPrefixes(array($__DIR__))
->install();
}

Expand Down
27 changes: 17 additions & 10 deletions lib/Raven/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function __construct($options_or_dsn = null, $options = array())
$this->curl_method = Raven_Util::get($options, 'curl_method', 'sync');
$this->curl_path = Raven_Util::get($options, 'curl_path', 'curl');
$this->curl_ipv4 = Raven_Util::get($options, 'curl_ipv4', true);
$this->ca_cert = Raven_Util::get($options, 'ca_cert', static::get_default_ca_cert());
$this->ca_cert = Raven_Util::get($options, 'ca_cert', self::get_default_ca_cert());
$this->verify_ssl = Raven_Util::get($options, 'verify_ssl', true);
$this->curl_ssl_version = Raven_Util::get($options, 'curl_ssl_version');
$this->trust_x_forwarded_proto = Raven_Util::get($options, 'trust_x_forwarded_proto');
Expand All @@ -177,7 +177,7 @@ public function __construct($options_or_dsn = null, $options = array())
$this->setAppPath(Raven_Util::get($options, 'app_path', null));
$this->setExcludedAppPaths(Raven_Util::get($options, 'excluded_app_paths', null));
// a list of prefixes used to coerce absolute paths into relative
$this->setPrefixes(Raven_Util::get($options, 'prefixes', static::getDefaultPrefixes()));
$this->setPrefixes(Raven_Util::get($options, 'prefixes', self::getDefaultPrefixes()));
$this->processors = $this->setProcessorsFromOptions($options);

$this->_lasterror = null;
Expand All @@ -202,7 +202,7 @@ public function __construct($options_or_dsn = null, $options = array())
}

$this->transaction = new Raven_TransactionStack();
if (static::is_http_request() && isset($_SERVER['PATH_INFO'])) {
if ($this->is_http_request() && isset($_SERVER['PATH_INFO'])) {
// @codeCoverageIgnoreStart
$this->transaction->push($_SERVER['PATH_INFO']);
// @codeCoverageIgnoreEnd
Expand Down Expand Up @@ -299,7 +299,7 @@ public function getAppPath()
public function setAppPath($value)
{
if ($value) {
$this->app_path = static::_convertPath($value);
$this->app_path = self::_convertPath($value);
} else {
$this->app_path = null;
}
Expand Down Expand Up @@ -394,7 +394,7 @@ public static function getDefaultProcessors()
public function setProcessorsFromOptions($options)
{
$processors = array();
foreach (Raven_util::get($options, 'processors', static::getDefaultProcessors()) as $processor) {
foreach (Raven_util::get($options, 'processors', self::getDefaultProcessors()) as $processor) {
/**
* @var Raven_Processor $new_processor
* @var Raven_Processor|string $processor
Expand Down Expand Up @@ -689,7 +689,7 @@ protected function registerShutdownFunction()
* @return bool
* @codeCoverageIgnore
*/
protected static function is_http_request()
protected function is_http_request()
{
return isset($_SERVER['REQUEST_METHOD']) && PHP_SAPI !== 'cli';
}
Expand Down Expand Up @@ -788,7 +788,7 @@ public function capture($data, $stack = null, $vars = null)
$data['extra'] = array();
}
if (!isset($data['event_id'])) {
$data['event_id'] = static::uuid4();
$data['event_id'] = self::uuid4();
}

if (isset($data['message'])) {
Expand All @@ -797,7 +797,7 @@ public function capture($data, $stack = null, $vars = null)

$data = array_merge($this->get_default_data(), $data);

if (static::is_http_request()) {
if ($this->is_http_request()) {
$data = array_merge($this->get_http_data(), $data);
}

Expand Down Expand Up @@ -981,7 +981,7 @@ public function send(&$data)
$message = $this->encode($data);

$headers = array(
'User-Agent' => static::getUserAgent(),
'User-Agent' => self::getUserAgent(),
'X-Sentry-Auth' => $this->getAuthHeader(),
'Content-Type' => 'application/octet-stream'
);
Expand Down Expand Up @@ -1028,6 +1028,13 @@ protected function get_curl_options()
$options[CURLOPT_SSLVERSION] = $this->curl_ssl_version;
}
if ($this->curl_ipv4) {
// some versions of PHP 5.2 don't have this defined correctly
if (!defined('CURLOPT_IPRESOLVE')) {
define('CURLOPT_IPRESOLVE', 113);
}
if (!defined('CURL_IPRESOLVE_V4')) {
define('CURL_IPRESOLVE_V4', 1);
}
$options[CURLOPT_IPRESOLVE] = CURL_IPRESOLVE_V4;
}
if (defined('CURLOPT_TIMEOUT_MS')) {
Expand Down Expand Up @@ -1196,7 +1203,7 @@ public function getAuthHeader()
{
$timestamp = microtime(true);
return $this->get_auth_header(
$timestamp, static::getUserAgent(), $this->public_key, $this->secret_key
$timestamp, self::getUserAgent(), $this->public_key, $this->secret_key
);
}

Expand Down
6 changes: 3 additions & 3 deletions lib/Raven/Stacktrace.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public static function get_stack_info($frames,
Raven_Serializer $serializer = null,
Raven_ReprSerializer $reprSerializer = null)
{
$serializer = $serializer ?: new Raven_Serializer();
$reprSerializer = $reprSerializer ?: new Raven_ReprSerializer();
$serializer = $serializer === null ? new Raven_Serializer() : $serializer;
$reprSerializer = $reprSerializer === null ? new Raven_ReprSerializer() : $reprSerializer;

/**
* PHP stores calls in the stacktrace, rather than executing context. Sentry
Expand Down Expand Up @@ -79,7 +79,7 @@ public static function get_stack_info($frames,

// detect in_app based on app path
if ($app_path) {
$norm_abs_path = @realpath($abs_path) ?: $abs_path;
$norm_abs_path = @realpath($abs_path) ? @realpath($abs_path) : $abs_path;
$in_app = (bool)(substr($norm_abs_path, 0, strlen($app_path)) === $app_path);
if ($in_app && $excluded_app_paths) {
foreach ($excluded_app_paths as $path) {
Expand Down
26 changes: 20 additions & 6 deletions test/Raven/Tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function simple_function($a=null, $b=null, $c=null)

function invalid_encoding()
{
$fp = fopen(__DIR__ . '/../../data/binary', 'r');
$fp = fopen(Helper_Php52::getDir() . '/../../data/binary', 'r');
simple_function(fread($fp, 64));
fclose($fp);
}
Expand All @@ -42,7 +42,7 @@ public function send(&$data)
$this->__sent_events[] = $data;
}

public static function is_http_request()
protected function is_http_request()
{
return true;
}
Expand Down Expand Up @@ -143,7 +143,7 @@ class Dummy_Raven_Client_No_Http extends Dummy_Raven_Client
/**
* @return bool
*/
public static function is_http_request()
protected function is_http_request()
{
return false;
}
Expand Down Expand Up @@ -1003,7 +1003,7 @@ public function testCaptureExceptionInLatin1File()

$client = new Dummy_Raven_Client($options);

require_once(__DIR__.'/resources/captureExceptionInLatin1File.php');
require_once(Helper_Php52::getDir() . '/resources/captureExceptionInLatin1File.php');

$events = $client->getSentEvents();
$event = array_pop($events);
Expand Down Expand Up @@ -1565,8 +1565,8 @@ public function test_convertPath()
$this->assertEquals('/foo/bar/', $property->invoke(null, '/foo/bar/'));
$this->assertEquals('foo/bar', $property->invoke(null, 'foo/bar'));
$this->assertEquals('foo/bar/', $property->invoke(null, 'foo/bar/'));
$this->assertEquals(dirname(__DIR__).'/', $property->invoke(null, __DIR__.'/../'));
$this->assertEquals(dirname(dirname(__DIR__)).'/', $property->invoke(null, __DIR__.'/../../'));
$this->assertEquals(dirname(Helper_Php52::getDir()) . '/', $property->invoke(null, Helper_Php52::getDir() . '/../'));
$this->assertEquals(dirname(dirname(Helper_Php52::getDir())) . '/', $property->invoke(null, Helper_Php52::getDir() . '/../../'));
}

/**
Expand Down Expand Up @@ -2230,3 +2230,17 @@ public function testClose_curl_resource()
$this->assertNull($reflection->getValue($raven));
}
}

class Helper_Php52
{
public static $__DIR__ = null;

public static function getDir()
{
if (null === self::$__DIR__) {
self::$__DIR__ = version_compare(PHP_VERSION, '5.3.0', '>=') ? __DIR__ : dirname(__FILE__);
}

return self::$__DIR__;
}
}
2 changes: 1 addition & 1 deletion test/Raven/Tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function send(&$data)
}
$this->__sent_events[] = $data;
}
public static function is_http_request()
protected function is_http_request()
{
return true;
}
Expand Down

0 comments on commit cbdb640

Please sign in to comment.