Download the PHP package weew/error-handler without Composer

On this page you can find all versions of the php package weew/error-handler. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package error-handler

Error handler

Build Status Code Quality Test Coverage Version Licence

Table of contents

Installation

composer require weew/error-handler

Introduction

This little library allows you to easily handle exceptions, recoverable and fatal errors globally in your code. Some types of errors are recoverable some are not, this kind of error handling should be used as last resort to do some logging, etc.

Enabling error handling

You can manually toggle between three kinds of errors that the error handler can handle: exceptions, recoverable and fatal errors.

You can always check whether some kind of error handling has been enabled.

About error handlers

Error handlers are small pieces of logic that you can register on the ErrorHandler. There are two different kinds of handlers: error and exception handlers. They all follow the same pattern: a handler accepts and abstraction of the occurred error / exception and returns a boolean value determining whether the error has bee handled or not. If the error has been handled, error handlers must return true, returning false is optional.

Error handling

In PHP there are two different kind of errors, the ones that you can recover from and the ones you can't. You can differentiate between them if you want to. All PHP errors are converted to an instance of IError. It will contain all the relevant information about the occurred error and be passed down to your error handlers.

Abstraction of PHP errors

All PHP errors are converted to an instance of IError. It serves as a holder for all the relevant error information and makes it accessible trough few getter methods.

There is also a very useful ErrorType class that holds information about all kinds of PHP errors and might be used to get error type name based on the error type number, check if a particular type of error is recoverable or not, and so on.

Handling recoverable PHP errors

Creating an error handler for recoverable errors.

Handling fatal PHP errors

Creating an error handler for fatal errors.

Handling both kinds of errors

Creating an error handler that covers both, recoverable and fatal errors.

Sophisticated error handlers

If you do not want to work with callbacks, you can create a sophisticated error handler class. All you have to do is to implement the INativeErrorHandler interface.

Exception handling

Error handler allows you to define the types of exceptions you want to handle in your exception handler. There are two ways you can plug in an exception handler: using callbacks or using an implementation of the IExceptionHandler interface.

Exception handler callbacks

When using simple callables / callbacks as exception handlers, all you have to do is to define the exception type in the function signature. Error handler will then figure out what kind of exceptions are supported by your exception handler and give it only the ones it can handle. Same as with errors, exception handlers must return true in order to tell that exception has been handled.

Below is an example of an exception handler that handles only exceptions of type HttpException or it's subclasses.

Sophisticated exception handlers

You can add an exception handler by passing in an instance of IExceptionHandler. When an exception is thrown, error handler will ask your custom exception handler whether it supports this kind of exceptions and if so, ask your handler to handle this exception.

Converting errors to exceptions

When a php errors occurres, it will be converted to an instance of IError and passed down to you error handlers. This requires you to differentiate between errors and exceptions. If you prefer dealing with errors as if they were regular exceptions, you can do so by telling the error handler to convert all php errors to appropriate exceptions. Do not forget to enable exception handling, otherwise you will not be able to handle them anymore.

Now, whenever for example an E_WARNING occurres, you'll get a WarningException. To handle all WarningException occurrences you can create a regular exception handler.

If you want to deal with all PHP errors that are converted to an exception in the same handler, you can create an exception handler for the IErrorException interface.

Below is a full list of available exceptions.

Error type Exception name
E_COMPILE_ERROR CompileErrorException
E_COMPILE_WARNING CompileWarningException
E_CORE_ERROR CoreErrorException
E_CORE_WARNING CoreWarningException
E_DEPRECATED DeprecatedException
E_ERROR ErrorException
E_NOTICE NoticeException
E_PARSE ParseException
E_RECOVERABLE_ERROR RecoverableErrorException
E_STRICT StrictException
E_USER_DEPRECATED UserDeprecatedException
E_USER_ERROR UserErrorException
E_USER_NOTICE UserNoticeException
E_USER_WARNING UserWarningException
E_WARNING WarningException

All exceptions listed above share the same IErrorException interface that offers some getters to access the error information.


All versions of error-handler with dependencies

PHP Build Version
Package Version
Requires weew/helpers-array Version ^1.0
weew/helpers-string Version ^1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package weew/error-handler contains the following files

Loading the files please wait ....