Skip to content
Merged
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
74 changes: 40 additions & 34 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,57 @@ name: PHP Composer

on:
push:
branches: [ "master" ]
branches: ["master"]
pull_request:
branches: [ "master" ]
branches: ["master"]

permissions:
contents: read

jobs:
build:
runs-on: ${{ matrix.operating-system }}
continue-on-error: ${{ matrix.experimental || false }}
strategy:
matrix:
operating-system: [ 'ubuntu-latest', 'windows-latest', 'macos-latest' ]
php-versions: [ '8.1', '8.2', '8.3' ]
phpunit-versions: [ 'latest' ]
operating-system: ["ubuntu-latest", "windows-latest", "macos-latest"]
php-versions: ["8.1", "8.2", "8.3", "8.4"]
phpunit-versions: ["latest"]
include:
- operating-system: 'ubuntu-latest'
php-versions: '8.0'
- operating-system: "ubuntu-latest"
php-versions: "8.0"
phpunit-versions: 9
experimental: true
- operating-system: "ubuntu-latest"
php-versions: "8.1"
phpunit-versions: "latest"
experimental: true
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, intl
ini-values: post_max_size=256M, max_execution_time=180
coverage: xdebug
tools: php-cs-fixer, phpunit:${{ matrix.phpunit-versions }}
- uses: actions/checkout@v3
- name: Check PHP Version
run: php -v
- name: Validate composer.json and composer.lock
run: composer validate --strict
- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
run: composer install --prefer-dist --no-progress
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, intl
ini-values: post_max_size=256M, max_execution_time=180
coverage: xdebug
tools: php-cs-fixer, phpunit:${{ matrix.phpunit-versions }}
- uses: actions/checkout@v3
- name: Check PHP Version
run: php -v
- name: Validate composer.json and composer.lock
run: composer validate --strict
- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
run: composer install --prefer-dist --no-progress

# Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit"
# Docs: https://getcomposer.org/doc/articles/scripts.md
- name: Run test suite
run: composer run-script test
# Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit"
# Docs: https://getcomposer.org/doc/articles/scripts.md
- name: Run test suite
run: composer run-script test
19 changes: 10 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:8.1-fpm-alpine
FROM php:8.3-fpm-alpine

RUN apk add --update \
git \
Expand All @@ -7,7 +7,8 @@ RUN apk add --update \
bash \
g++ \
vim \
make
make \
linux-headers

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer

Expand All @@ -18,18 +19,18 @@ ARG php_ini_dir="/usr/local/etc/php"
RUN mv "$php_ini_dir/php.ini-production" "$PHP_INI_DIR/php.ini"

# @see https://xdebug.org/docs/compat
# Xdebug 3.1
# Xdebug 3.3+ for PHP 8.3

ARG xdebug_client_host="127.0.0.1"
ARG xdebug_client_port=9003

RUN echo $php_ini_dir

RUN apk update
RUN apk add --upgrade php81-pecl-xdebug \
&& echo "zend_extension=/usr/lib/php81/modules/xdebug.so" > $php_ini_dir/conf.d/99-xdebug.ini \
&& echo "xdebug.client_port=$xdebug_client_port" >> $php_ini_dir/conf.d/99-xdebug.ini \
&& echo "xdebug.client_host=$xdebug_client_host" >> $php_ini_dir/conf.d/99-xdebug.ini \
&& echo "xdebug.mode=debug,develop,coverage" >> $php_ini_dir/conf.d/99-xdebug.ini
# Install Xdebug via PECL for PHP 8.3
RUN pecl install xdebug \
&& docker-php-ext-enable xdebug \
&& echo "xdebug.client_port=$xdebug_client_port" >> $php_ini_dir/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.client_host=$xdebug_client_host" >> $php_ini_dir/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.mode=debug,develop,coverage" >> $php_ini_dir/conf.d/docker-php-ext-xdebug.ini

WORKDIR /app
48 changes: 36 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@


[![Coverage Status](https://coveralls.io/repos/emgiezet/errbitPHP/badge.png)](https://coveralls.io/r/emgiezet/errbitPHP)
[![Build Status](https://travis-ci.org/emgiezet/errbitPHP.png?branch=master)](https://travis-ci.org/emgiezet/errbitPHP)
[![Dependency Status](https://www.versioneye.com/user/projects/5249e725632bac0a4900b2bf/badge.png)](https://www.versioneye.com/user/projects/5249e725632bac0a4900b2bf)
[![Build Status](https://github.com/emgiezet/errbit-php/actions/workflows/ci.yml/badge.svg)](https://github.com/emgiezet/errbit-php/actions/workflows/ci.yml)
[![Latest Stable Version](https://poser.pugx.org/emgiezet/errbit-php/v/stable.png)](https://packagist.org/packages/emgiezet/errbit-php)
[![SymfonyInsight](https://insight.symfony.com/projects/a0c405fb-8ee9-40e9-acf1-eee084fc35a6/mini.svg)](https://insight.symfony.com/projects/a0c405fb-8ee9-40e9-acf1-eee084fc35a6)
[![Join the chat at https://gitter.im/emgiezet/errbitPHP](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/emgiezet/errbitPHP?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

This is a full-featured client to add integration with [Errbit](https://github.com/errbit/errbit) (or Airbrake)
to any PHP 8.0 and 8.1 application.
to any PHP 8.2+ application.

## PHP Version Requirements

| Library Version | PHP Version |
|-----------------|--------------------------------|
| 1.x | PHP 5.3 |
| 2.x | PHP 8.0, 8.1 |
| **3.x** | **PHP 8.2, 8.3** (recommended) |

Original idea and source has no support for php namespaces.
Moreover it has a bug and with newest errbit version the xml has not supported chars.
Expand All @@ -21,28 +27,46 @@ Check the presentation below!

[![Huston whe have an Airbrake](http://image.slidesharecdn.com/hustonwehaveanairbrake-131125152637-phpapp02/95/slide-1-638.jpg?1385415083)](http://www.slideshare.net/MaxMaecki/meetphp-11-huston-we-have-an-airbrake)

## Upgrading to v3.0

Version 3.0 contains breaking changes. If you're upgrading from v2.x, please note:

- **PHP 8.0 and 8.1 support has been dropped** - Minimum PHP version is now 8.2
- **Removed `ErrorInterface`** - Use `\Throwable` type hints instead
- **Changed `WriterInterface::write()` signature** - Now accepts `\Throwable` instead of `ErrorInterface`
- **Updated error class constructors** - `Notice`, `Warning`, `Error`, `Fatal` now use named parameters

## ChangeLog

Check the:

[![Full change log here](Resources/doc/changlelog.md)]
[![Releases](https://github.com/emgiezet/errbitPHP/releases)]
- [Full change log here](Resources/doc/changlelog.md)
- [Releases](https://github.com/emgiezet/errbitPHP/releases)

## Installation

### Composer Way
For php 5.3
For PHP 5.3
```json
require: {
...
"emgiezet/errbit-php": "1.*"
}
}
```
For php 8.0+

For PHP 8.0, 8.1

```json
require: {
...
"emgiezet/errbit-php": "2.*"
}
}
```

For PHP 8.2+ (recommended)

```json
require: {
"emgiezet/errbit-php": "^3.0"
}
```

## Usage
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"issues": "https://github.com/emgiezet/errbitPHP/issues"
},
"require": {
"php": "^8.0||8.1||8.2||^8.3",
"php": "^8.1||^8.2||^8.3||^8.4",
"guzzlehttp/guzzle": "^7.5.0",
"ext-simplexml": "*"
},
Expand All @@ -37,7 +37,7 @@
"mockery/mockery": "1.5.1",
"phpunit/phpunit": "9.4.4",
"php-coveralls/php-coveralls": "^2.5",
"vimeo/psalm": "^5.6",
"vimeo/psalm": "^6.0",
"phpstan/phpstan": "^1.9"
},
"replace": {
Expand Down
3 changes: 3 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
<psalm
errorLevel="3"
resolveFromConfigFile="true"
phpVersion="8.4"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
findUnusedBaselineEntry="true"
findUnusedCode="false"
>
<projectFiles>
<directory name="src" />
Expand Down
21 changes: 8 additions & 13 deletions src/Errbit/Errbit.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@
declare(strict_types=1);
namespace Errbit;

use Errbit\Errors\ErrorInterface;
use Errbit\Errors\Warning;
use Errbit\Exception\ConfigurationException;
use Errbit\Exception\Exception;

use Errbit\Errors\Notice;
use Errbit\Errors\Error;
use Errbit\Errors\Fatal;
use Errbit\Handlers\ErrorHandlers;
use Errbit\Writer\WriterInterface;

Expand Down Expand Up @@ -138,13 +132,13 @@ public function start(array $handlers = ['exception', 'error', 'fatal']): static
/**
* Notify an individual exception manually.
*
* @param \Errbit\Errors\ErrorInterface $exception
* @param \Throwable $exception
* @param array $options
*
* @return static [Errbit] the current instance
* @throws \Errbit\Exception\ConfigurationException
*/
public function notify(ErrorInterface $exception, array $options = []): static
public function notify(\Throwable $exception, array $options = []): static
{
$this->checkConfig();
$config = array_merge($this->config, $options);
Expand All @@ -158,20 +152,21 @@ public function notify(ErrorInterface $exception, array $options = []): static
}

/**
* @param \Errbit\Errors\ErrorInterface $exception
* @param \Throwable $exception
* @param array $skippedExceptions
*
* @return bool
*/
protected function shouldNotify(ErrorInterface $exception, array $skippedExceptions): bool
protected function shouldNotify(\Throwable $exception, array $skippedExceptions): bool
{
foreach ($skippedExceptions as $skippedException) {
if ($exception instanceof $skippedException) {
return false;
}
}
$userAgent = $_SERVER['HTTP_USER_AGENT'] ?? '';
foreach ($this->config['ignore_user_agent'] as $ua) {
if (str_contains($_SERVER['HTTP_USER_AGENT'],$ua) ) {
if ($userAgent !== '' && str_contains($userAgent, $ua)) {
return false;
}
}
Expand All @@ -180,12 +175,12 @@ protected function shouldNotify(ErrorInterface $exception, array $skippedExcepti
}

/**
* @param \Errbit\Errors\ErrorInterface $exception
* @param \Throwable $exception
* @param array $config
*
* @return void
*/
protected function notifyObservers(ErrorInterface $exception, array $config): void
protected function notifyObservers(\Throwable $exception, array $config): void
{
foreach ($this->observers as $observer) {
$observer($exception, $config);
Expand Down
68 changes: 25 additions & 43 deletions src/Errbit/Errors/BaseError.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,38 @@
declare(strict_types=1);
namespace Errbit\Errors;

use Throwable;

/**
*
*/
abstract class BaseError
abstract class BaseError extends \Exception
{
/**
* Create a new error wrapping the given error context info.
*
* @param string $message message
* @param integer $line line
* @param string $file filename
* @param array $trace
*/
public function __construct(private string $message, private int $line, private string $file, private array $trace)
{
}
/**
* Message getter
*
* @return string error message
*
*/
public function getMessage(): string
{
return $this->message;
}
/**
* Line getter
*
* @return integer the number of line
*/
public function getLine(): int
{
return $this->line;
protected string $errorFile = '';
protected array $backtrace = [];

public function __construct(
string $message = "",
int $code = 0,
?Throwable $previous = null,
string $file = '',
array $backtrace = []
) {
parent::__construct($message, $code, $previous);
$this->errorFile = $file;
$this->backtrace = $backtrace;
if ($file !== '') {
$this->file = $file;
}
}
/**
* File getter
*
* @return string name of the file
*/
public function getFile(): string

public function getErrorFile(): string
{
return $this->file;
return $this->errorFile;
}

/**
* @return array
*/
public function getTrace(): array

public function getBacktrace(): array
{
return $this->trace;
return $this->backtrace;
}
}
Loading
Loading