Obviously I would have remembered to rename my example class there if I 
weren't about to go to bed.

Catch you all tomorrow!

On Tuesday, 21 February 2017 21:55:24 UTC, John Porter wrote:
>
> I was right about the prototype issues, my tests have been fixing those.
>
> Here's my interpretation then of of the ResponseTime middleware:
>
> <?php
>
> namespace Example;
>
> use Psr\Http\Message\MessageInterface;
> use Psr\Http\Message\RequestInterface;
> use Psr\Http\Middleware\RequestMiddlewareInterface;
> use Psr\Http\Middleware\ResponseMiddlewareInterface;
>
>
> class AuthHeaderMiddleware implements RequestMiddlewareInterface, 
> ResponseMiddlewareInterface
> {
>     const HEADER = 'X-Response-Time';
>
>     private $startTime;
>
>     public function parseRequest(RequestInterface $request): 
> MessageInterface
>     {
>         $server = $request->getServerParams();
>         $this->startTime = isset($server['REQUEST_TIME_FLOAT']) ? $server[
> 'REQUEST_TIME_FLOAT'] : microtime(true);
>     }
>
>     public function parseResponse(ResponseInterface $response): 
> ResponseInterface
>     {
>         return $response->withHeader(self::HEADER, sprintf('%2.3fms', (
> microtime(true) - $this->startTime) * 1000));
>     }
> }
>
> Because the middleware implements both interfaces, it would be applied 
> (using my Stack example) in both directions. Hope this helps.
>
>
>
> On Tuesday, 21 February 2017 20:07:32 UTC, Michael Mayer wrote:
>>
>> Am Dienstag, 21. Februar 2017 20:50:10 UTC+1 schrieb John Porter:
>>>
>>> Can you explain what you mean by prototype related issues?
>>>
>>
>> I only see some issues with your code which are unrelated to your idea, 
>> that's all.
>>
>> Where would the computation time be added, to a request or response? Can 
>>> you show me how you’d achieve it with the double pass method, and I can 
>>> show you the alternative.
>>>
>>
>> No implementation of a another middleware needed, but 
>> Middlewares\ResponseTime 
>> <https://github.com/middlewares/response-time/blob/master/src/ResponseTime.php>
>>  would 
>> be an example. Anyway with a PSR-15 stack dispatcher, like 
>> Middlewares\Utils\Dispatcher 
>> <https://github.com/middlewares/utils#dispatcher>, we can do:
>>
>> $dispatcher = new Dispatcher([
>>     new ResponseTimeMiddleware(),
>>     new AuthMiddleware(),
>>     …
>> ]);
>>
>> $response = $dispatcher->dispatch(new ServerRequest());
>>
>

-- 
You received this message because you are subscribed to the Google Groups "PHP 
Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to php-fig+unsubscr...@googlegroups.com.
To post to this group, send email to php-fig@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/php-fig/734f80ea-cc78-4579-a2d9-96675336fb43%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to