Download the PHP package ctw/ctw-middleware-httpexception without Composer

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

Package "ctw/ctw-middleware-httpexception"

Latest Stable Version GitHub Actions

PSR-15 middleware that catches HTTP exceptions and renders custom error pages for production environments, with automatic JSON support for API requests.

Introduction

Why This Library Exists

Web applications need graceful error handling that presents user-friendly error pages in production while preserving detailed error information during development. The default PHP error handling exposes sensitive information and provides poor user experience.

This middleware integrates with ctw/ctw-http exceptions to:

Problems This Library Solves

  1. Generic error pages: Default framework error pages are ugly and expose technical details
  2. Missing JSON errors: API clients receive HTML error pages instead of structured JSON
  3. Development vs production: Need different error handling behavior per environment
  4. Inconsistent responses: Different error codes handled inconsistently across the application
  5. Security exposure: Stack traces and internal paths leak in production errors

Where to Use This Library

Design Goals

  1. Content negotiation: Serves HTML or JSON based on client Accept header
  2. RFC 7807 compliance: JSON errors follow Problem Details specification
  3. Template-based rendering: Uses Mezzio template renderer for HTML responses
  4. Development awareness: Re-throws exceptions when development mode is enabled
  5. Exception hierarchy: Only catches HttpExceptionInterface, re-throws others

Requirements

Installation

Install by adding the package as a Composer requirement:

Usage Examples

Basic Pipeline Registration (Mezzio)

ConfigProvider Registration

Throwing HTTP Exceptions

HTML Response (Browser)

When a browser requests a page and an exception occurs:

JSON Response (API)

When a client sends Accept: application/json:

Configuration Options

Option Description Default
template_http_exception Template name for HTML error pages error::http-exception.phtml
layout Layout template for error pages (none)

Template Variables

The error template receives:

Variable Type Description
entity HttpStatus HTTP status entity with code, name, phrase
exception HttpExceptionInterface The caught exception
layout string Layout template name (if configured)

Development Mode

In development mode (when laminas/laminas-development-mode is enabled), exceptions are re-thrown to allow the Whoops error handler or similar tools to display detailed debugging information.


All versions of ctw-middleware-httpexception with dependencies

PHP Build Version
Package Version
Requires php Version ^8.5
ctw/ctw-http Version ^5.0
laminas/laminas-diactoros Version ^3.0
mezzio/mezzio-template Version ^2.4
psr/container Version ^1.0 || ^2.0
psr/http-message Version ^1.1 || ^2.0
psr/http-server-handler Version ^1.0
psr/http-server-middleware 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 ctw/ctw-middleware-httpexception contains the following files

Loading the files please wait ...