번역 : 스페인어
예외 처리를 위한 PHP 라이브러리입니다.
예외를 처리하려면 예외 처리기 라이브러리를 사용할 수 있습니다.
운영 체제: 리눅스 | 윈도우.
PHP 버전: 8.1.
이 확장을 설치하는 기본 방법은 Composer를 사용하는 것입니다.
PHP ErrorHandler 라이브러리를 설치하려면 다음을 수행하세요.
composer require josantonius/error-handler
사용할 수 있는 전체 소스 코드를 다운로드 하려는 경우 이전 명령은 필요한 파일만 설치합니다.
composer require josantonius/error-handler --prefer-source
Git을 사용하여 전체 저장소를 복제 할 수도 있습니다.
git clone https://github.com/josantonius/php-error-handler.git
JosantoniusErrorHandlerErrorException
ErrorException을 확장합니다.
오류 파일을 가져옵니다.
public function getFile(): string ;
오류 수준을 가져옵니다.
public function getLevel(): int ;
오류 파일 라인을 가져옵니다.
public function getLine(): int ;
오류 메시지를 받습니다:
public function getMessage(): string ;
오류 이름을 가져옵니다.
public function getName(): string ;
JosantoniusErrorHandlerErrorHandled
오류 파일을 가져옵니다.
public function getFile(): string ;
오류 수준을 가져옵니다.
public function getLevel(): int ;
오류 파일 라인을 가져옵니다.
public function getLine(): int ;
오류 메시지가 나타납니다:
public function getMessage(): string ;
오류 이름을 가져옵니다.
public function getName(): string ;
JosantoniusErrorHandlerErrorHandler
오류를 예외로 변환:
/**
* The errors will be thrown from the ErrorException instance.
*
* @param int[] $errorLevel Define the specific error levels that will become exceptions.
*
* @throws WrongErrorLevelException if error level is not valid.
*
* @see https://www.php.net/manual/en/errorfunc.constants.php to view available error levels.
*/
public function convertToExceptions( int ... $ errorLevel ): ErrorHandler ;
일부를 제외하고 오류를 예외로 변환합니다.
/**
* The errors will be thrown from the ErrorException instance.
*
* @param int[] $errorLevel Define the specific error levels that will become exceptions.
*
* @throws WrongErrorLevelException if error level is not valid.
*
* @see https://www.php.net/manual/en/errorfunc.constants.php to view available error levels.
*/
public function convertToExceptionsExcept( int ... $ errorLevel ): ErrorHandler ;
오류 처리기 함수를 등록합니다.
/**
* The error handler will receive the ErrorHandled object.
*
* @see https://www.php.net/manual/en/functions.first_class_callable_syntax.php
*/
public function register( callable $ callback ): ErrorHandler ;
오류 보고를 사용하여 어떤 오류가 처리되는지 확인하세요.
/**
* If the setting value in error_reporting() is used to determine which errors are handled.
*
* If this method is not used, all errors will be sent to the handler.
*
* @see https://www.php.net/manual/en/function.error-reporting.php
*/
public function useErrorReportingLevel(): ErrorHandler ;
use Josantonius ErrorHandler Exceptions WrongErrorLevelException ;
이 라이브러리의 사용 예:
use Josantonius ErrorHandler ErrorHandler ;
$ errorHandler = new ErrorHandler ();
$ errorHandler -> convertToExceptions ();
// All errors will be converted to exceptions.
use Josantonius ErrorHandler ErrorHandler ;
$ errorHandler = new ErrorHandler ();
$ errorHandler -> convertToExceptions ( E_USER_ERROR , E_USER_WARNING );
// Only E_USER_ERROR and E_USER_WARNING will be converted to exceptions.
use Josantonius ErrorHandler ErrorHandler ;
$ errorHandler = new ErrorHandler ();
$ errorHandler -> convertToExceptionsExcept ( E_USER_DEPRECATED , E_USER_NOTICE );
// All errors except E_USER_DEPRECATED and E_USER_NOTICE will be converted to exceptions.
use Josantonius ErrorHandler ErrorHandler ;
error_reporting ( E_USER_ERROR );
$ errorHandler = new ErrorHandler ();
$ errorHandler -> convertToExceptions ()-> useErrorReportingLevel ();
// Only E_USER_ERROR will be converted to exception.
use ErrorException ;
use Josantonius ErrorHandler ErrorHandler ;
set_exception_handler ( function ( ErrorException $ exception ) {
var_dump ([
' level ' => $ exception -> getLevel (),
' message ' => $ exception -> getMessage (),
' file ' => $ exception -> getFile (),
' line ' => $ exception -> getLine (),
' name ' => $ exception -> getName (),
]);
});
$ errorHandler = new ErrorHandler ();
$ errorHandler -> convertToExceptions ();
// All errors will be converted to exceptions.
use Josantonius ErrorHandler ErrorHandled ;
use Josantonius ErrorHandler ErrorHandler ;
function handler ( Errorhandled $ errorHandled ): void {
var_dump ([
' level ' => $ errorHandled -> getLevel (),
' message ' => $ errorHandled -> getMessage (),
' file ' => $ errorHandled -> getFile (),
' line ' => $ errorHandled -> getLine (),
' name ' => $ errorHandled -> getName (),
]);
}
$ errorHandler = new ErrorHandler ();
$ errorHandler -> register (
callback: handler (...)
);
// All errors will be converted to exceptions.
use Josantonius ErrorHandler ErrorHandled ;
use Josantonius ErrorHandler ErrorHandler ;
class Handler {
public static function errors ( Errorhandled $ exception ): void { /* do something */ }
}
$ errorHandler = new ErrorHandler ();
$ errorHandler -> register (
callback: Handler:: errors (...)
)-> convertToExceptions ();
// The error will be sent to the error handler and then throw the exception.
error_reporting ( E_USER_ERROR );
class Handler {
public function errors ( Errorhandled $ exception ): void { /* do something */ }
}
$ handler = new Handler ();
$ errorHandled -> register (
callback: $ handler -> errors (...),
)-> convertToExceptions ()-> useErrorReportingLevel ();
// Only E_USER_ERROR will be passed to the handler and converted to exception.
테스트를 실행하려면 작곡가가 필요하고 다음을 실행해야 합니다.
git clone https://github.com/josantonius/php-error-handler.git
cd php-error-handler
composer install
PHPUnit을 사용하여 단위 테스트를 실행합니다.
composer phpunit
PHPCS를 사용하여 코드 표준 테스트를 실행합니다.
composer phpcs
PHP Mess Detector 테스트를 실행하여 코드 스타일의 불일치를 감지합니다.
composer phpmd
이전 테스트를 모두 실행합니다.
composer tests
각 릴리스에 대한 자세한 변경 사항은 릴리스 노트에 설명되어 있습니다.
끌어오기 요청을 하기 전에 기여 가이드를 읽고 토론을 시작하거나 문제를 보고하십시오.
모든 기여자에게 감사드립니다! ❤️
이 프로젝트가 귀하의 개발 시간을 줄이는 데 도움이 된다면, 저의 오픈 소스 작업을 지원하도록 후원해 주실 수 있습니까?
이 저장소는 MIT 라이선스에 따라 라이선스가 부여됩니다.
저작권 © 2016-현재, Josantonius