php-http / message

HTTP Message related tools
http://php-http.org
MIT License
1.3k stars 42 forks source link

Formatter #14

Closed sagikazarmark closed 8 years ago

sagikazarmark commented 8 years ago

We should be able to format Requests/Responses to string.

Basic interface

<?php

namespace Http\Message;

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

/**
 * Formats a request or a response into string.
 *
 * @author Márk Sági-Kazár <mark.sagikazar@gmail.com>
 */
interface Formatter
{
    /**
     * Formats a request.
     *
     * @param RequestInterface $request
     *
     * @return string
     */
    public function formatRequest(RequestInterface $request);

    /**
     * Formats a response.
     *
     * @param ResponseInterface $response
     *
     * @return string
     */
    public function formatResponse(ResponseInterface $response);
}

Some questions

dbu commented 8 years ago

+1 not sure about separating. a guzzle formatter makes absolutely no sense for a response. but it could just reuse the simple text formatter for the response and do its cool stuff on requests. that way, things are much simpler than having two interfaces that 90% of the time are provided by the same formatter.