Mezzio Documentation

repository·3.29.x·Indexed 18 days ago

https://github.com/mezzio/mezzio

Mezzio is a minimalist PSR-7 middleware framework for PHP built on laminas-stratigility. It provides a flexible architecture for building applications using pluggable components for routing (such as FastRoute and laminas-router), PSR-11 compliant dependency injection containers, and optional templating engines like Plates, Twig, and Laminas's PhpRenderer. The framework is designed around PSR-15 middleware and PSR-7 HTTP messages.

Tokens
166.4K
Snippets
472
Records
578
Agent score
58%

What's inside Mezzio

  1. What is Mezzio?

    3.29.x

    Mezzio is a minimalist PSR-7 middleware framework for PHP built on top of laminas-stratigility. It is designed for developing middleware applications quickly by providing a flexible architecture where you can choose your own components for routing, dependency injection, and templating.

    Key features include:

    • Routing: Supports multiple routers like FastRoute and laminas-router.
    • DI Containers: Uses PSR-11 compliant containers. Middleware matched via routing is retrieved from the composed container.
    • Templating (Optional): Supports Plates, Twig, and Laminas's PhpRenderer.
  2. Overview of available Mezzio Helpers

    3.29.x

    Mezzio provides several helper utilities and middleware to handle common application tasks. The current helpers include:

    • Body Params Middleware: Middleware for handling request body parameters.
    • Content-Length Middleware: Middleware for managing content-length (available since mezzio-helpers 4.1.0).
    • UrlHelper: A utility for generating URLs.
    • ServerUrlHelper: A utility for generating server-side URLs.
  3. Overview of Mezzio features

    3.29.x

    Mezzio is a minimalist PSR-7 middleware framework for PHP built on top of Stratigility. It provides a flexible foundation that allows you to choose your own components for routing, dependency injection, and templating. Key features include:

    • Routing: Supports multiple routers including Aura.Router, FastRoute, and laminas-router.
    • DI Containers: Uses PSR-11 compliant containers. All middleware composed in Mezzio can be retrieved from the composed container.
    • Templating: Supports Plates, Twig, and Laminas's PhpRenderer.
    • Error Handling: Supports templated error pages or debugging tools like whoops.
    • Middleware Composition: Supports nested middleware applications, allowing you to compose an application under a separate subpath within another application.
  4. Overview of Mezzio features and architecture

    3.29.x

    Mezzio is a minimalist PSR-15 middleware framework for PHP built on top of Stratigility. It is designed to be unopinionated, allowing developers to choose their own components for routing, dependency injection, and templating.

    Key architectural features include:

    • Routing: Supports multiple routers including Aura.Router, FastRoute, and laminas-router.
    • Dependency Injection: Uses PSR-11 containers. All middleware composed within Mezzio can be retrieved from the composed container.
    • Templating: Supports Plates, Twig, and laminas-view's PhpRenderer.
    • Middleware Composition: Supports nested middleware applications, allowing you to compose an application within another, potentially under a specific subpath.
    • Error Handling: Supports custom templated error pages and debugging tools like Whoops.
  5. Overview of Mezzio features and capabilities

    3.29.x

    Mezzio is a minimalist PSR-7 middleware framework built on top of Stratigility. It is designed to be unopinionated, allowing you to choose your own components for routing, dependency injection, and templating.

    Key features include:

    • Routing: Supports multiple routers including Aura.Router, FastRoute, and laminas-router.
    • DI Containers: Uses container-interop (PSR-11). All middleware composed in Mezzio can be retrieved from the composed container.
    • Templating: Supports Plates, Twig, and Laminas's PhpRenderer.
    • Error Handling: Supports templated error pages or debugging tools like whoops.
    • Nested Middleware: Allows composing applications within other applications, potentially under separate subpaths.
    • Flexible Installation: Provides a Composer-based installer to customize your initial stack.
  6. Core features of Mezzio

    3.29.x

    Mezzio provides a convenience layer built on laminas-stratigility with the following key features:

    • Dynamic Routing: Unlike basic literal matching, Mezzio supports dynamic routing. It abstracts the routing library, allowing you to use Aura.Router, FastRoute, or laminas-mvc. It also handles HTTP method restrictions and returns 405 Not Allowed responses automatically.
    • PSR-11 Container Integration: The Application class composes a PSR-11 ContainerInterface to enable Dependency Injection and lazy-loading of middleware.
    • Templating Abstraction: Provides an abstraction that allows middleware to typehint on a templating service, supporting layouts and namespaced templates regardless of the underlying adapter.
    • Error Handling: Provides error handling via Stratigility's ErrorHandler, including specialized response generators for templating or using Whoops.
  7. Core features of Mezzio

    3.29.x

    Mezzio is a flexible microframework designed around several key standards and pluggable components:

    • PSR-15 Middleware: Build applications using standard middleware layers.
    • PSR-7 HTTP Messages: Uses standard PHP interfaces for HTTP requests and responses.
    • Pluggable Routing: Route requests using any routing library that implements the required interfaces.
    • Dependency Injection: Use any PSR-11 compliant container to manage dependencies.
    • Templating: Create templated responses using various template engines.
    • Error Handling: Gracefully handle errors using templated pages, tools like Whoops, or custom solutions.
  8. Mezzio core features overview

    3.29.x

    Mezzio provides several key capabilities for building web applications:

    • Powerful Routing: Supports dynamic routing and fine-grained matching. It can restrict routes to specific HTTP methods and automatically returns 405 Not Allowed responses with an Allow header for invalid methods.
    • PSR-11 Container: Uses a PSR-11 ContainerInterface to facilitate dependency injection and lazy-load middleware.
    • Flexible Templating: Provides an abstraction layer for templating. While it doesn't assume a specific engine, it provides wrappers for Plates, Twig, and laminas-view.
    • Error Handling: Integrates with Stratigility's ErrorHandler for specialized error response generation and supports Whoops for development.
  9. Overview of provided Mezzio factories

    3.29.x
    Mezzio provides several PSR-11 compatible factories to simplify the setup of common dependencies within your application container. These factories can be used to instantiate core components like the Application, Emitter, Error Handler, and various middleware-related services. When configuring your container, you can map these factories to their suggested service names to ensure all necessary dependencies are correctly wired.
  10. What is Mezzio and how does it work?

    3.29.x

    Mezzio is a framework for writing PSR-7 compliant middleware applications. It uses the concept of an "onion" or a FIFO (First-In-First-Out) queue to process HTTP requests and responses.

    Core Concepts

    • PSR-7: The standard defining HTTP message interfaces (Request and Response) used by Mezzio to ensure interoperability.
    • Middleware: Code that sits between a request and a response. Middleware typically analyzes a request, delegates processing, and returns a response. Middleware is designed to be composable and reusable.
    • The Pipeline (The Onion): The Application acts as a queue. The first middleware attached is executed first. Each middleware can either:
      1. Return a response, which stops the queue and causes execution to wind back out through the previous middleware layers.
      2. Call the next middleware to continue the traversal.

    Workflow Summary

    • The application is a queue operating in FIFO order.
    • Responses are returned through the pipeline in reverse order of traversal.
    • You control the application workflow by deciding the order in which middleware is queued.
  11. What is a Mezzio Application and how does it work?

    3.29.x

    A Mezzio\Application instance is a middleware component that orchestrates the request/response lifecycle. It composes several key elements:

    • A router for matching requests to middleware.
    • A dependency injection container (PSR-11) for retrieving middleware services.
    • A default delegate (or final handler) to handle cases where the middleware pipeline is exhausted without a response.
    • An emitter to send the final response to the client.

    You can define the application via direct instantiation, using the AppFactory (deprecated since 2.2), or via a container factory.

  12. What is a Mezzio Application?

    3.29.x

    In Mezzio, the Mezzio\Application instance is the central orchestrator. It is itself a middleware that composes several key components:

    • A Router: For dynamically matching incoming requests to specific middleware.
    • A Dependency Injection Container: For retrieving middleware services.
    • A Final Handler: To handle error conditions or cases where no response was returned by the pipeline.
    • An Emitter: To send the final response to the client.

    You can instantiate an application via direct constructor injection, using the AppFactory for convenience, or via a container factory.