Download the PHP package phpdot/error without Composer

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

phpdot/error

Structured error codes with context, translatable messages, and uniform output across every channel. Optional translator integration via phpdot/contracts.


Table of Contents

Requirements

Requirement Constraint
PHP >= 8.5
phpdot/contracts ^0.5

Installation

Usage

Quick Start

1. Define errors for your module:

2. Collect errors:

3. Same output everywhere:


How It Works

Add flow

Two ways to construct a bag

Package Structure

7 files. Single optional dependency on phpdot/contracts for the cross-package translator interface.


Defining Error Codes

ErrorCodeInterface

Every module defines a backed string enum implementing this interface:

ErrorCodeTrait

Provides the default implementation. The trait reads from getDetails() — you only implement one method:

Module Error Enums

Each module owns its errors. No central error file.

Error Code Convention


ErrorEntry (The DTO)

Pure data. No translation, no escaping. Immutable.


ErrorBag (The Collector)

Adding Errors

Checking Errors

Filtering Errors

Merging Bags

Combine errors from sub-operations:

HTTP Status

Derived from the first error. If empty, returns 500.

Serialization

Clear and reset:


ErrorBagFactory

Produces fresh ErrorBag instances pre-wired with an optional translator. Inject the factory once, call create() whenever you need a new bag — translator threading happens automatically.

Each create() call returns a new, independent bag — no shared state between calls.

Auto-wired usage

When using phpdot/container, services that need to produce errors inject the factory directly. The translator is wired into the factory through the container and passed to every bag the factory produces — without the service ever importing MessageTranslatorInterface:

The factory is #[Scoped] so each execution unit (request, coroutine) gets its own instance with its own per-request translator.


ErrorType (9 Categories)

The frontend uses the type to decide presentation (red badge for server, yellow for validation, etc.). The error code gives the specific problem.


HttpStatus (Typed Enum)

IDE autocompletion and compile-time safety for HTTP status codes:


Context

Context is what the error relates to. Not just form fields.

Filter by context to show errors next to the right element:


Translation (i18n)

How Translation Works

The error package stores translation keys, not translated text. Translation happens at render time.

ICU Params

Dynamic values for translation interpolation. Works with any ICU-compatible i18n library — phpdot/i18n is one option, but not required.

Frontend Translation

The frontend receives the error code and description key, translates in its own i18n system:

Server-Side Translation

With any translation library:

Auto-Translation via MessageTranslatorInterface

ErrorBag accepts an optional PHPdot\Contracts\I18n\MessageTranslatorInterface in its constructor. When wired, every add() call replaces the entry's description field with the translator's output for the original key + ICU params:

The message field is never touched by the bag — it always carries the enum's English string (developer-facing documentation). The description field is the runtime-variable one: the raw translation key when no translator is wired, or the translated string when one is.

The bag does not second-guess the translator. Whatever the translator returns — including a [key] sentinel for missing keys — goes straight into description. Fallback policy is the translator's responsibility, not the bag's.

MessageTranslatorInterface ships in phpdot/contracts. phpdot/i18n's Translator already implements it, but any compatible translator works.


Output Formats

JSON API

HTML Forms

CLI

WebSocket

Same $bag->toArray() serialized as JSON. Identical structure to the API.


Real-World Usage

Service Validation

Cross-Module Merge

Frontend Grouping


API Reference

ErrorCodeInterface API

ErrorCodeTrait API

ErrorEntry API

ErrorBag API

ErrorType API

HttpStatus API

Case Value
OK 200
CREATED 201
ACCEPTED 202
NO_CONTENT 204
MOVED_PERMANENTLY 301
FOUND 302
NOT_MODIFIED 304
TEMPORARY_REDIRECT 307
PERMANENT_REDIRECT 308
BAD_REQUEST 400
UNAUTHORIZED 401
FORBIDDEN 403
NOT_FOUND 404
METHOD_NOT_ALLOWED 405
CONFLICT 409
GONE 410
PAYLOAD_TOO_LARGE 413
UNSUPPORTED_MEDIA 415
UNPROCESSABLE_ENTITY 422
TOO_MANY_REQUESTS 429
INTERNAL_SERVER_ERROR 500
BAD_GATEWAY 502
SERVICE_UNAVAILABLE 503
GATEWAY_TIMEOUT 504

Architecture

One error. One code. One structure. Every channel. Every language.

Testing

The package is standalone-testable:

License

MIT.

This repository is a read-only mirror, generated by CI from phpdot/monorepo. Pull requests and issues belong in the monorepo.


All versions of error with dependencies

PHP Build Version
Package Version
Requires php Version >=8.5
phpdot/contracts Version ^0.6
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 phpdot/error contains the following files

Loading the files please wait ...