Giter Site home page Giter Site logo

relay.middleware's Introduction

Relay Middleware

This package include the following Relay-compatible middleware:

  • ResponseSender to send a PSR-7 response
  • ExceptionHandler to handler exceptions from subsequent middleware

This package is installable and PSR-4 autoloadable via Composer as relay/middleware.

ResponseSender

The ResponseSender does just what it sounds like: it sends the PSR-7 response object.

The ResponseSender does nothing with the $request or $response, passing them immediately to $next. Afterwards, it takes the returned $response and sends it using header() and echo, and returns the sent $response.

The ResponseSender is intended to go at the top of the Relay queue, so that it is the middleware with the last opportunity to do something with the returned response.

To add the ResponseSender to your Real queue, instantiate it directly ...

$queue[] = new \Relay\Middleware\ResponseSender();

... or use a $resolver of your choice to instantiate it from the $queue.

ExceptionHandler

Similarly, the ExceptionHandler does what it sound like: it catches any exceptions that bubble up through the following middleware decorators.

The ExceptionHandler does nothing with the $request or $response, and passes them directly to $next inside a try/catch block. If no exception bubbles up, it returns the $response from $next. However, if it catches an exception, it returns an entirely new $response object with the exception message and an HTTP 500 status code. It then returns the new $response object.

The ExceptionHandler is intended to go near the top of the Relay queue, but after the ResponseSender, so that the ResponseSender can then send the returned $response.

To add the ExceptionHandler to your queue, instantiate it directly with an empty $response implementation object ...

$queue = new \Relay\Middleware\ExceptionHandler(new ResponseImplementation());

... or use a $resolver of your choice to instantiate it from the $queue.

relay.middleware's People

Watchers

Bryan J. Agee avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.