Download the PHP package andreacivita/heimdal without Composer

On this page you can find all versions of the php package andreacivita/heimdal. 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 heimdal

Heimdal [WiP]

Latest Stable Version Build Status Coverage Status Total Downloads

This project is a fork of esbenp/heimdal. Purpose of this fork is support Laravel 6+ version. All credits goes to Esbenp

Introduction

Heimdal is a Laravel exception handler build specifically for APIs.

Why is it needed?

When building APIs there are specific formatting do's and dont's on how to send errors back to the user. Frameworks like Laravel are not build specifically for API builders. This small library just bridges that gap. For instance, specifications like JSON API have guidelines for how errors should be formatted.

Installation

Add the service provider to config/app.php

Publish the configuration.

Add the exception handler to bootstrap/app.php

What does it do?

Imagine you have a piece of code that throws an InvalidArgumentException. This is a server error (500). It will parse through the flow described below.

Is this not what Laravel does?

Yes, pretty much. However, if you want to report to something like Sentry you usually do this through something like Monolog. The problem with Monolog is that it is difficult to pick up the response of the reporters. For instance, Sentry reports back a unique ID for every reported exception which is extremely useful to give to the user, so they can give it to customer support. Heimdal supports this out-of-the-box by giving the response of all reporters to the formatter classes. This makes it trivial for formatters to use the response of the reporters in their final response to the user.

Second, Heimdal comes with sensible defaults as how different error types should be reported to the user. And makes it trivial to implement alternative responses for specific exception types.

Configuration

Heimdal has two things that should be configured: formatters and reporters.

Reporters

You should determine where your exceptions should be reported to. Heimdal still calls the base report function in Laravel, so your exceptions will still be logged as normal. However, adding external reporting is easy. Heimdal comes with Sentry integration out of the box. To send exceptions to Sentry simply add this entry to the reporters section in config/andreacivita.heimdal.php

Adding a custom reporter, for instance Bugsnag, is as simple as writing a small reporter class like this

And then add it to config/andreacivita.heimdal.php

Formatters

Heimdal already comes with sensible formatters out of the box. In config/andreacivita.heimdal.php is a section where the formatter priority is defined.

The higher the entry, the higher the priority. In this example, a UnprocessableEntityHttpException will be formatted used the UnprocessableEntityHttpExceptionFormatter because it is the first entry. However, an NotFoundHttpException will not match UnprocessableEntityHttpException but will match HttpException (since it is a child class hereof) and will therefore be formatted using the HttpExceptionFormatter.

You can write custom formatters easily:

Notice how easily we used $reporterResponses to attach the ID of the Sentry log to the JSON response. Now we simply add it to config/andreacivita.heimdal.php

Now all NotFoundHttpExceptions will be formatted using our custom formatter.

Available Reporters

Sentry

To send Exceptions to Sentry add the following reporter configuration in config/andreacivita.heimdal.php.

Adding context at runtime

Sometimes you want to add information at runtime, like request data, user information or similar. For this you can add the add_context key to the config array. Below is an example of how it could be implemented.

Bugsnag

Thanks to Nikolaj Løvenhardt Petersen for adding support

Install Bugsnag using the Laravel installation guide

To send Exceptions to Bugsnag add the following reporter configuration in config/andreacivita.heimdal.php.

Rollbar

To send Exceptions to Rollbar add the following reporter configuration in config/andreacivita.heimdal.php.

The complete list of config options can be found in here

Standards

This package is compliant with PSR-1, PSR-2 and PSR-4. If you notice compliance oversights, please send a patch via pull request.

Testing

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT). Please see License File for more information.


All versions of heimdal with dependencies

PHP Build Version
Package Version
Requires laravel/framework Version ~5.3|~6.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 andreacivita/heimdal contains the following files

Loading the files please wait ....