-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a90fee4
Showing
15 changed files
with
483 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Ignore all test and documentation for archive | ||
/.github export-ignore | ||
/.gitattributes export-ignore | ||
/.gitignore export-ignore | ||
/.scrutinizer.yml export-ignore | ||
/phpunit.xml.dist export-ignore | ||
/tests export-ignore | ||
/docs export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# These are supported funding model platforms | ||
|
||
github: [klimov-paul] | ||
patreon: klimov_paul |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
### What steps will reproduce the problem? | ||
|
||
### What is the expected result? | ||
|
||
### What do you get instead? | ||
|
||
### Additional info | ||
|
||
| Q | A | ||
|-----------------------| --- | ||
| This Package Version | 1.?.? | ||
| Yii Framework Version | 1.1.? | ||
| PHP version | | ||
| Operating system | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
| Q | A | ||
| ------------- | --- | ||
| Is bugfix? | ✔️/❌ | ||
| New feature? | ✔️/❌ | ||
| Breaks BC? | ✔️/❌ | ||
| Tests pass? | ✔️/❌ | ||
| Fixed issues | comma-separated list of tickets # fixed by the PR, if any |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: build | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
phpunit: | ||
name: PHP ${{ matrix.php }} on ${{ matrix.os }} | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ubuntu-latest] | ||
php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3'] | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
extensions: mbstring | ||
tools: composer:v2 | ||
coverage: none | ||
|
||
- name: Install dependencies | ||
run: | | ||
composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi | ||
- name: Run unit tests | ||
run: vendor/bin/phpunit --colors=always |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# phpstorm project files | ||
.idea | ||
|
||
# netbeans project files | ||
nbproject | ||
|
||
# zend studio for eclipse project files | ||
.buildpath | ||
.project | ||
.settings | ||
|
||
# windows thumbnail cache | ||
Thumbs.db | ||
|
||
# composer vendor dir | ||
/vendor | ||
|
||
/composer.lock | ||
|
||
# composer itself is not needed | ||
composer.phar | ||
|
||
# Mac DS_Store Files | ||
.DS_Store | ||
|
||
# phpunit itself is not needed | ||
phpunit.phar | ||
# local phpunit config | ||
/phpunit.xml | ||
# phpunit cache | ||
.phpunit.result.cache | ||
|
||
# test runtime files | ||
/.phpunit.cache | ||
/tests/runtime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Yii1 Enhanced Error Handler extension | ||
===================================== | ||
|
||
1.0.0 Under Development | ||
----------------------- | ||
|
||
- Initial release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
This is free software. It is released under the terms of the | ||
following BSD License. | ||
|
||
Copyright © 2023 by Yii1Tech (https://github.com/yii1tech) | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions | ||
are met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in | ||
the documentation and/or other materials provided with the | ||
distribution. | ||
* Neither the name of Yii1Tech nor the names of its | ||
contributors may be used to endorse or promote products derived | ||
from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<p align="center"> | ||
<a href="https://github.com/yii1tech" target="_blank"> | ||
<img src="https://avatars.githubusercontent.com/u/134691944" height="100px"> | ||
</a> | ||
<h1 align="center">Yii1 Enhanced Error Handler</h1> | ||
<br> | ||
</p> | ||
|
||
This extension provides Enhanced Error Handler for Yii1 application. | ||
|
||
For license information check the [LICENSE](LICENSE.md)-file. | ||
|
||
[![Latest Stable Version](https://img.shields.io/packagist/v/yii1tech/error-handler.svg)](https://packagist.org/packages/yii1tech/error-handler) | ||
[![Total Downloads](https://img.shields.io/packagist/dt/yii1tech/error-handler.svg)](https://packagist.org/packages/yii1tech/error-handler) | ||
[![Build Status](https://github.com/yii1tech/error-handler/workflows/build/badge.svg)](https://github.com/yii1tech/error-handler/actions) | ||
|
||
|
||
Installation | ||
------------ | ||
|
||
The preferred way to install this extension is through [composer](http://getcomposer.org/download/). | ||
|
||
Either run | ||
|
||
``` | ||
php composer.phar require --prefer-dist yii1tech/error-handler | ||
``` | ||
|
||
or add | ||
|
||
```json | ||
"yii1tech/error-handler": "*" | ||
``` | ||
|
||
to the "require" section of your composer.json. | ||
|
||
|
||
Usage | ||
----- | ||
|
||
This extension provides Enhanced Error Handler for Yii1 application. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"name": "yii1tech/error-handler", | ||
"description": "Provides Enhanced Error Handler for Yii1 application", | ||
"keywords": ["yii1", "error", "handler", "exception"], | ||
"license": "BSD-3-Clause", | ||
"support": { | ||
"issues": "https://github.com/yii1tech/error-handler/issues", | ||
"wiki": "https://github.com/yii1tech/error-handler/wiki", | ||
"source": "https://github.com/yii1tech/error-handler" | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Paul Klimov", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": ">=7.2", | ||
"yiisoft/yii": "~1.1.0" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^6.0 || ^7.0 || ^8.0 || ^9.3 || ^10.0.7" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"yii1tech\\error\\handler\\": "src" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"yii1tech\\error\\handler\\test\\": "tests" | ||
} | ||
}, | ||
"extra": { | ||
"branch-alias": { | ||
"dev-master": "1.0.x-dev" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<phpunit bootstrap="./tests/bootstrap.php" | ||
colors="true" | ||
backupGlobals="true" | ||
backupStaticProperties="false" | ||
processIsolation="false" | ||
cacheDirectory=".phpunit.cache" | ||
stopOnError="false" | ||
stopOnFailure="false"> | ||
<testsuites> | ||
<testsuite name="Yii1tech Test Suite"> | ||
<directory>./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?php | ||
|
||
namespace yii1tech\error\handler; | ||
|
||
use CErrorHandler; | ||
use ErrorException; | ||
use Yii; | ||
|
||
/** | ||
* Application configuration example: | ||
* | ||
* ``` | ||
* [ | ||
* 'preload' => [ | ||
* 'errorHandler', // override default error handler, allowing error to exception conversion | ||
* // ... | ||
* ], | ||
* 'components' => [ | ||
* 'errorHandler' => [ | ||
* 'class' => \yii1tech\error\handler\ErrorHandler::class, | ||
* ], | ||
* // ... | ||
* ], | ||
* // ... | ||
* ] | ||
* ``` | ||
* | ||
* @author Paul Klimov <[email protected]> | ||
* @since 1.0 | ||
*/ | ||
class ErrorHandler extends CErrorHandler | ||
{ | ||
/** | ||
* @var bool whether to convert PHP Errors into Exceptions. | ||
* @see \ErrorException | ||
*/ | ||
public $convertErrorToException = true; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function init() | ||
{ | ||
parent::init(); | ||
|
||
if (YII_ENABLE_ERROR_HANDLER) { | ||
restore_error_handler(); // unset default Yii error handler, which is set to {@see \CApplication::handleError()} | ||
|
||
set_error_handler([$this, 'handleErrorGlobal'], error_reporting()); | ||
} | ||
} | ||
|
||
/** | ||
* Handles global PHP execution errors such as warnings, notices. | ||
* | ||
* This method is implemented as a PHP error handler. It requires | ||
* that constant `YII_ENABLE_ERROR_HANDLER` be defined true. | ||
* | ||
* @param int $code the level of the error raised | ||
* @param string $message the error message | ||
* @param string $file the filename that the error was raised in | ||
* @param int $line the line number the error was raised at | ||
* @return bool whether the normal error handler continues. | ||
*/ | ||
public function handleErrorGlobal(int $code, string $message, string $file, int $line): bool | ||
{ | ||
if (!$this->convertErrorToException) { | ||
Yii::app()->handleError($code, $message, $file, $line); | ||
|
||
return false; | ||
} | ||
|
||
if (error_reporting() & $code) { | ||
$exception = new ErrorException($message, $code, $code, $file, $line); | ||
|
||
$trace = debug_backtrace(); | ||
array_shift($trace); | ||
$this->setExceptionTrace($exception, $trace); | ||
|
||
if (PHP_VERSION_ID < 70400) { | ||
// prior to PHP 7.4 we can't throw exceptions inside of __toString() - it will result a fatal error | ||
foreach ($trace as $frame) { | ||
if ($frame['function'] === '__toString') { | ||
Yii::app()->handleException($exception); | ||
|
||
return false; | ||
} | ||
} | ||
} | ||
|
||
throw $exception; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* Sets up the trace for the given exception. | ||
* | ||
* > Note: exception trace can't be modified and used directly with PHP, thus a reflection is used here. | ||
* | ||
* @param \Exception $exception exception instance. | ||
* @param array $trace new stack trace. | ||
*/ | ||
protected function setExceptionTrace(\Exception $exception, array $trace): void | ||
{ | ||
$traceReflection = new \ReflectionProperty(\Exception::class, 'trace'); | ||
$traceReflection->setAccessible(true); | ||
$traceReflection->setValue($exception, $trace); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace yii1tech\error\handler\test; | ||
|
||
class ErrorHandlerTest extends TestCase | ||
{ | ||
public function testCovertErrorToException(): void | ||
{ | ||
try { | ||
$this->withYiiErrorHandler(function () { | ||
trigger_error('Test message', E_USER_WARNING); | ||
}); | ||
} catch (\Throwable $exception) {} | ||
|
||
$this->assertTrue(isset($exception)); | ||
$this->assertSame('Test message', $exception->getMessage()); | ||
$this->assertSame(E_USER_WARNING, $exception->getCode()); | ||
|
||
$trace = $exception->getTrace(); | ||
|
||
$this->assertSame('trigger_error', $trace[0]['function']); | ||
$this->assertFalse(empty($trace[0]['args'])); | ||
} | ||
} |
Oops, something went wrong.