PHPackages                             rnd-cosoft/api-tools-api-problem - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. rnd-cosoft/api-tools-api-problem

ActiveLibrary[HTTP &amp; Networking](/categories/http)

rnd-cosoft/api-tools-api-problem
================================

Laminas Module providing API-Problem assets and rendering

1.7.1(1y ago)02.0k↓100%19BSD-3-ClausePHPPHP ~8.1.0 || ~8.2.0 || ~8.3.0

Since Dec 31Pushed 1y agoCompare

[ Source](https://github.com/rnd-cosoft/api-tools-api-problem)[ Packagist](https://packagist.org/packages/rnd-cosoft/api-tools-api-problem)[ Docs](https://api-tools.getlaminas.org)[ RSS](/packages/rnd-cosoft-api-tools-api-problem/feed)WikiDiscussions 1.7.x Synced 1mo ago

READMEChangelog (2)Dependencies (11)Versions (28)Used By (9)

Laminas Api Problem
===================

[](#laminas-api-problem)

[![Build Status](https://github.com/laminas-api-tools/api-tools-api-problem/actions/workflows/continuous-integration.yml/badge.svg)](https://github.com/laminas-api-tools/api-tools-api-problem/actions/workflows/continuous-integration.yml)

> ## 🇷🇺 Русским гражданам
>
> [](#-русским-гражданам)
>
> Мы, участники Laminas, родились и живем в разных странах. У многих из нас есть друзья, родственники и коллеги как в России, так и в Украине. Некоторые из нас родились в России. Некоторые из нас живут в России. У некоторых бабушки и дедушки сражались с фашистами во Второй мировой войне. Здесь никто не поддерживает фашизм.
>
> У одного из нас есть украинская родственница, которая спаслась из дома вместе с сыном. Поезд задержался из-за бомбежки на дороге впереди. У нас есть друзья, которые прячутся в бомбоубежищах. Мы с тревогой ждем весточки от них после воздушных налетов, которые беспорядочно наносят удары и попадают по больницам, школам, детским садам и домам. Мы не берем это из каких-либо СМИ. Мы наблюдаем это напрямую.
>
> Вы доверяете нам достаточно, чтоб использовать наши программы, и мы просим вас довериться нам вновь. Мы нуждаемся в помощи. Выходите и протестуйте против этой бесполезной войны. Остановите кровопролитие. Скажите "Нет войне!"
>
> ## 🇺🇸 To Citizens of Russia
>
> [](#-to-citizens-of-russia)
>
> We at Laminas come from all over the world. Many of us have friends, family and colleagues in both Russia and Ukraine. Some of us were born in Russia. Some of us currently live in Russia. Some have grandparents who fought Nazis in World War II. Nobody here supports fascism.
>
> One team member has a Ukrainian relative who fled her home with her son. The train was delayed due to bombing on the road ahead. We have friends who are hiding in bomb shelters. We anxiously follow up on them after the air raids, which indiscriminately fire at hospitals, schools, kindergartens and houses. We're not taking this from any media. These are our actual experiences.
>
> You trust us enough to use our software. We ask that you trust us to say the truth on this. We need your help. Go out and protest this unnecessary war. Stop the bloodshed. Say "stop the war!"

Introduction
------------

[](#introduction)

This module provides data structures and rendering for the API-Problem format.

- [Problem Details for HTTP APIs](https://tools.ietf.org/html/rfc7807), used for reporting API problems.

Requirements
------------

[](#requirements)

Please see the [composer.json](composer.json) file.

Installation
------------

[](#installation)

Run the following `composer` command:

```
$ composer require laminas-api-tools/api-tools-api-problem
```

Alternately, manually add the following to your `composer.json`, in the `require` section:

```
"require": {
    "laminas-api-tools/api-tools-api-problem": "^1.2"
}
```

And then run `composer update` to ensure the module is installed.

Finally, add the module name to your project's `config/application.config.php` under the `modules`key:

```
return [
    /* ... */
    'modules' => [
        /* ... */
        'Laminas\ApiTools\ApiProblem',
    ],
    /* ... */
];
```

> ### laminas-component-installer
>
> [](#laminas-component-installer)
>
> If you use [laminas-component-installer](https://github.com/laminas/laminas-component-installer), that plugin will install api-tools-api-problem as a module for you.

Configuration
=============

[](#configuration)

### User Configuration

[](#user-configuration)

The top-level configuration key for user configuration of this module is `api-tools-api-problem`.

#### Key: accept\_filters

[](#key-accept_filters)

An array of `Accept` header media types that, when matched, will result in the [ApiProblemListener](#laminasapiproblemlistenerapiproblemlistener) handling an `MvcEvent::EVENT_RENDER_ERROR` event.

#### Key: render\_error\_controllers

[](#key-render_error_controllers)

An array of controller service names that, if matched as the `controller` parameter in the MVC `RouteMatch`, will cause the [ApiProblemListener](#laminasapiproblemlistenerapiproblemlistener) to handle `MvcEvent::EVENT_RENDER_ERROR` events.

### System Configuration

[](#system-configuration)

The following configuration is provided in `config/module.config.php` to enable the module to function:

```
'service_manager' => [
    'aliases'   => [
        'Laminas\ApiTools\ApiProblem\ApiProblemListener'  => 'Laminas\ApiTools\ApiProblem\Listener\ApiProblemListener',
        'Laminas\ApiTools\ApiProblem\RenderErrorListener' => 'Laminas\ApiTools\ApiProblem\Listener\RenderErrorListener',
        'Laminas\ApiTools\ApiProblem\ApiProblemRenderer'  => 'Laminas\ApiTools\ApiProblem\View\ApiProblemRenderer',
        'Laminas\ApiTools\ApiProblem\ApiProblemStrategy'  => 'Laminas\ApiTools\ApiProblem\View\ApiProblemStrategy',
    ],
    'factories' => [
        'Laminas\ApiTools\ApiProblem\Listener\ApiProblemListener'             => 'Laminas\ApiTools\ApiProblem\Factory\ApiProblemListenerFactory',
        'Laminas\ApiTools\ApiProblem\Listener\RenderErrorListener'            => 'Laminas\ApiTools\ApiProblem\Factory\RenderErrorListenerFactory',
        'Laminas\ApiTools\ApiProblem\Listener\SendApiProblemResponseListener' => 'Laminas\ApiTools\ApiProblem\Factory\SendApiProblemResponseListenerFactory',
        'Laminas\ApiTools\ApiProblem\View\ApiProblemRenderer'                 => 'Laminas\ApiTools\ApiProblem\Factory\ApiProblemRendererFactory',
        'Laminas\ApiTools\ApiProblem\View\ApiProblemStrategy'                 => 'Laminas\ApiTools\ApiProblem\Factory\ApiProblemStrategyFactory',
    ],
],
'view_manager' => [
    // Enable this in your application configuration in order to get full
    // exception stack traces in your API-Problem responses.
    'display_exceptions' => false,
],
```

Laminas Events
--------------

[](#laminas-events)

### Listeners

[](#listeners)

#### Laminas\\ApiTools\\ApiProblem\\Listener\\ApiProblemListener

[](#laminasapitoolsapiproblemlistenerapiproblemlistener)

The `ApiProblemListener` attaches to three events in the MVC lifecycle:

- `MvcEvent::EVENT_DISPATCH` as a *shared* listener on `Laminas\Stdlib\DispatchableInterface` with a priority of `100`.
- `MvcEvent::EVENT_DISPATCH_ERROR` with a priority of `100`.
- `MvcEvent::EVENT_RENDER` with a priority of `1000`.

If the current `Accept` media type does not match the configured API-Problem media types (by default, these are `application/json` and `application/*+json`), then this listener returns without taking any action.

When this listener does take action, the purposes are threefold:

- Before dispatching, the `render_error_controllers` configuration value is consulted to determine if the `Laminas\ApiTools\ApiProblem\Listener\RenderErrorListener` should be attached; see [RenderErrorListener](#rendererrorlistener) for more information.
- After dispatching, detects the type of response from the controller; if it is already an `ApiProblem` model, it continues without doing anything. If an exception was thrown during dispatch, it converts the response to an API-Problem response with some information from the exception.
- If a dispatch error occurred, and the `Accept` type is in the set defined for API-Problems, it attempts to cast the dispatch exception into an API-Problem response.

#### Laminas\\ApiTools\\ApiProblem\\Listener\\RenderErrorListener

[](#laminasapitoolsapiproblemlistenerrendererrorlistener)

This listener is attached to `MvcEvent::EVENT_RENDER_ERROR` at priority `100`. This listener is conditionally attached by `Laminas\ApiTools\ApiProblem\Listener\ApiProblemListener` for controllers that require API Problem responses. With a priority of `100`, this ensures that this listener runs before the default Laminas listener on this event. In cases when it does run, it will cast an exception into an API-problem response.

#### `Laminas\ApiTools\ApiProblem\Listener\SendApiProblemResponseListener`

[](#laminasapitoolsapiproblemlistenersendapiproblemresponselistener)

This listener is attached to `SendResponseEvent::EVENT_SEND_RESPONSE` at priority `-500`. The primary purpose of this listener is, on detection of an API-Problem response, to send appropriate headers and the problem details as the content body. If the `view_manager`'s `display_exceptions`setting is enabled, the listener will determine if the API-Problem represents an application exception, and, if so, inject the exception trace as part of the serialized response.

Laminas Services
----------------

[](#laminas-services)

### Event Services

[](#event-services)

- `Laminas\ApiTools\ApiProblem\Listener\ApiProblemListener`
- `Laminas\ApiTools\ApiProblem\Listener\RenderErrorListener`
- `Laminas\ApiTools\ApiProblem\Listener\SendApiProblemResponseListener`

### View Services

[](#view-services)

#### Laminas\\ApiTools\\ApiProblem\\View\\ApiProblemRenderer

[](#laminasapitoolsapiproblemviewapiproblemrenderer)

This service extends the `JsonRenderer` service from the Laminas MVC layer. Its primary responsibility is to decorate JSON rendering with the ability to optionally output stack traces.

#### Laminas\\ApiTools\\ApiProblem\\View\\ApiProblemStrategy

[](#laminasapitoolsapiproblemviewapiproblemstrategy)

This service is a view strategy that detects a `Laminas\ApiTools\ApiProblem\View\ApiProblemModel`; when detected, it selects the [ApiProblemRender](#laminasapiproblemviewapiproblemrenderer), and injects the response with a `Content-Type` header that contains the `application/problem+json` media type. This is similar in nature to Laminas's `JsonStrategy`.

### Models

[](#models)

#### Laminas\\ApiTools\\ApiProblem\\ApiProblem

[](#laminasapitoolsapiproblemapiproblem)

An instance of `Laminas\ApiTools\ApiProblem\ApiProblem` serves the purpose of modeling the kind of problem that is encountered. An instance of `ApiProblem` is typically wrapped in an [ApiProblemResponse](#laminasapiproblemapiproblemresponse). Most information can be passed into the constructor:

```
class ApiProblem
{
    public function __construct(
        $status,
        $detail,
        $type = null,
        $title = null,
        array $additional = []
    ) {
        /* ... */
    }
}
```

For example:

```
new ApiProblem(404, 'Entity not found');

// or

new ApiProblem(424, $exceptionInstance);
```

#### `Laminas\ApiTools\ApiProblem\ApiProblemResponse`

[](#laminasapitoolsapiproblemapiproblemresponse)

An instance of `Laminas\ApiTools\ApiProblem\ApiProblemResponse` can be returned from any controller service or Laminas MVC event in order to short-circuit the MVC lifecycle and immediately return a response. When it is, the response will be converted to the proper JSON structure for an API-Problem, and the `Content-Type` header will be set to the `application/problem+json` media type.

For example:

```
use Laminas\Mvc\Controller\AbstractActionController;
use Laminas\ApiTools\ApiProblem\ApiProblem;
use Laminas\ApiTools\ApiProblem\ApiProblemResponse;

class MyController extends AbstractActionController
{
    /* ... */
    public function fetch($id)
    {
        $entity = $this->model->fetch($id);
        if (! $entity) {
            return new ApiProblemResponse(new ApiProblem(404, 'Entity not found'));
        }
        return $entity;
    }
}
```

###  Health Score

42

—

FairBetter than 89% of packages

Maintenance32

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community27

Small or concentrated contributor base

Maturity82

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 86.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~59 days

Recently: every ~121 days

Total

28

Last Release

729d ago

Major Versions

0.9.1 → 1.0.02019-12-31

PHP version history (9 changes)0.6.0PHP &gt;=5.3.3

0.8.0PHP &gt;=5.4.8

0.9.0PHP &gt;=5.3.23

1.1.0PHP &gt;=5.5

1.2.0PHP ^5.6 || ^7.0

1.4.0PHP ^7.3 || ~8.0.0

1.5.0PHP ^7.3 || ~8.0.0 || ~8.1.0

1.6.0PHP ~8.0.0 || ~8.1.0 || ~8.2.0

1.7.0PHP ~8.1.0 || ~8.2.0 || ~8.3.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1388877?v=4)[Kristijonas Lučinskas](/maintainers/kristijonas)[@Kristijonas](https://github.com/Kristijonas)

---

Top Contributors

[![weierophinney](https://avatars.githubusercontent.com/u/25943?v=4)](https://github.com/weierophinney "weierophinney (691 commits)")[![michalbundyra](https://avatars.githubusercontent.com/u/7423207?v=4)](https://github.com/michalbundyra "michalbundyra (30 commits)")[![acabala](https://avatars.githubusercontent.com/u/530622?v=4)](https://github.com/acabala "acabala (11 commits)")[![Wilt](https://avatars.githubusercontent.com/u/2419627?v=4)](https://github.com/Wilt "Wilt (9 commits)")[![bakura10](https://avatars.githubusercontent.com/u/1198915?v=4)](https://github.com/bakura10 "bakura10 (8 commits)")[![MichaelGooden](https://avatars.githubusercontent.com/u/1275012?v=4)](https://github.com/MichaelGooden "MichaelGooden (8 commits)")[![telkins](https://avatars.githubusercontent.com/u/53731?v=4)](https://github.com/telkins "telkins (6 commits)")[![ralphschindler](https://avatars.githubusercontent.com/u/76674?v=4)](https://github.com/ralphschindler "ralphschindler (5 commits)")[![rnd-cosoft](https://avatars.githubusercontent.com/u/57006314?v=4)](https://github.com/rnd-cosoft "rnd-cosoft (3 commits)")[![ezimuel](https://avatars.githubusercontent.com/u/475967?v=4)](https://github.com/ezimuel "ezimuel (3 commits)")[![geerteltink](https://avatars.githubusercontent.com/u/9497586?v=4)](https://github.com/geerteltink "geerteltink (3 commits)")[![lukash82](https://avatars.githubusercontent.com/u/5096284?v=4)](https://github.com/lukash82 "lukash82 (3 commits)")[![Ocramius](https://avatars.githubusercontent.com/u/154256?v=4)](https://github.com/Ocramius "Ocramius (2 commits)")[![bartbrinkman](https://avatars.githubusercontent.com/u/8309358?v=4)](https://github.com/bartbrinkman "bartbrinkman (2 commits)")[![svycka](https://avatars.githubusercontent.com/u/1270782?v=4)](https://github.com/svycka "svycka (2 commits)")[![rogervila](https://avatars.githubusercontent.com/u/6053012?v=4)](https://github.com/rogervila "rogervila (1 commits)")[![rtuin](https://avatars.githubusercontent.com/u/360150?v=4)](https://github.com/rtuin "rtuin (1 commits)")[![samsonasik](https://avatars.githubusercontent.com/u/459648?v=4)](https://github.com/samsonasik "samsonasik (1 commits)")[![snapshotpl](https://avatars.githubusercontent.com/u/312655?v=4)](https://github.com/snapshotpl "snapshotpl (1 commits)")[![Xerkus](https://avatars.githubusercontent.com/u/725842?v=4)](https://github.com/Xerkus "Xerkus (1 commits)")

---

Tags

laminasrestmoduleapi-problemapi-tools

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/rnd-cosoft-api-tools-api-problem/health.svg)

```
[![Health](https://phpackages.com/badges/rnd-cosoft-api-tools-api-problem/health.svg)](https://phpackages.com/packages/rnd-cosoft-api-tools-api-problem)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
