Skip to content

Commit

Permalink
README update, dispatcher request changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jshannon63 committed Jan 8, 2018
1 parent 7a4228e commit 981b5ac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The laravel-psr15-middleware library (a.k.a. Psr15Middleware) is a Laravel compa
Once installed, you will be able to run compliant PSR-15 middleware in Laravel using this package's integration in the existing middleware stack.

#### PSR implementation reasoning. TL;DR
This package fully implements the PSR-7 (psr/http-message) message object interfaces. The interface is realized through Zend Diactoros concrete implementations of both the Request and Response objects. It also fully implements the proposed PSR-15 (http-interop/http-server-middleware) middleware and (http-interop/http-server-handler) request handler interfaces. However, it does not yet include the proposed PSR-17 (http-factory) factory interfaces for creating PSR-7 objects. This is due to the fact that we use the Symfony PSR-7 Bridge to make the conversions in both directions between HTTPFoundation and PSR-7 message objects.
This package fully implements the PSR-7 (psr/http-message) message object interfaces. The interface is realized through Zend Diactoros concrete implementations of both the Request and Response objects. It also fully implements the proposed PSR-15 (http-interop/http-server-middleware) middleware and (http-interop/http-server-handler) request handler interfaces. However, it does not yet include the proposed PSR-17 (http-factory) factory interfaces for creating PSR-7 objects. This is due to the fact that we use the Symfony PSR-7 Bridge to make the conversions in both directions between Foundation and PSR-7 message objects.

## Installation
Within your Laravel project folder, install this package using composer. If you are using Laravel 5.5 or later, service provider registration will happen automatically.
Expand Down Expand Up @@ -145,8 +145,6 @@ class exampleMiddleware implements MiddlewareInterface
All PSR-15 middleware is encapsulated and managed entirely by the PSR15Middleware subsystem. On boot, Psr15Middleware will bind a wrapper object for each PSR-15 middleware to make it appear native to Laravel. Then the objects will be placed into the Laravel middleware stack according to your configuration parameters. The middlewares themselves will only be instanitated as needed. Laravel will execute the middelwares according to the system priorites and as modified during registration of PSR-15 middlewares by Psr15Middleware.
Please note that PSR-7 Message objects are considered immutable, and we treat the Foundation message objects with the same respect. Psr15Middleware will work with cloned/converted Illuminate Response/Request objects while processing PSR-15 middlewares. This means that at every PSR-15 middleware, there will be new request and response objects regardless of whether or not they have changed by a middleware.
Also, keep in mind, that since Psr15Middlware operates on PSR-7 message objects, PSR-15 middlewares will not have access to Laravel/Symfony specific properties and methods of the Foundation message objects.
## Middleware Sources
Expand Down
25 changes: 8 additions & 17 deletions src/Psr15MiddlewareDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,17 @@ public function __invoke(FoundationRequest $request, FoundationResponse $respons

private function convertRequest($psr7request, $original)
{
$clone = clone $original;

$foundation_request = (new HttpFoundationFactory())->createRequest($psr7request);

$clone->attributes = $foundation_request->attributes;
$clone->request = $foundation_request->request;
$clone->server = $foundation_request->server;
$clone->query = $foundation_request->query;
$clone->files = $foundation_request->files;
$clone->cookies = $foundation_request->cookies;
$clone->headers = $foundation_request->headers;
$original->query = clone $foundation_request->query;
$original->request = clone $foundation_request->request;
$original->attributes = clone $foundation_request->attributes;
$original->cookies = clone $foundation_request->cookies;
$original->files = clone $foundation_request->files;
$original->server = clone $foundation_request->server;
$original->headers = clone $foundation_request->headers;

$clone->setRequestFormat($foundation_request->getRequestFormat());
$clone->setDefaultLocale($foundation_request->getDefaultLocale());
$clone->setLocale($foundation_request->getLocale());
if ($foundation_request->hasSession()) {
$clone->setSession($foundation_request->getSession());
}

return $clone;
return $original;
}

private function convertResponse($psr7response, $original)
Expand Down

0 comments on commit 981b5ac

Please sign in to comment.