RMR Architecture - At which point does it make sense to load the representation and headers?
<p>I am currently in the process of developing an open source RMR framework. At the moment a resource representation is loaded and parsed in the resource itself like in the following example (this is at abstraction level and some parts cut out to shorten this post):</p>

<pre><code>/**
 * Processes a given request and returns a response. Makes use of a 
 * data source for data retrieval and an array of parameters 
 * (usually passed in from the route).
 * 
 * @param  Request  $request
 * @param  mixed    $dataSource
 * @param  array    $parameters
 * @return Response
 */
public function processRequest(Request $request, $dataSource, array $parameters)
{
    $method = strtolower($request-&gt;getMethod());
    $this-&gt;dataSource = $dataSource;
    $this-&gt;parameters = $parameters;
    $this-&gt;request = $request;

    if(method_exists($this, $method))
    {
        // Something like get, post, head in resources
        $data = $this-&gt;$method();
        $response = new Response(StatusCode::HTTP_OK);

        if(empty($data))
        {
            // Do some stuff, return 200 ok no message-body etc.
        }

        // Find preferred media type in request accept
        $mediaType = $request-&gt;getMediaType();

        // .. loop through find representation  ..
        // Representation is reponsible for adding its own headers and body to
        // response, does this make sense to you?
        $representation-&gt;parse($response, $data);

        return $response;
    }
    else
    {
        return new Response(StatusCode::HTTP_METHOD_NOT_ALLOWED);
    }
}
</code></pre>

<p>So my question really is does it make sense to let the resource handle loading the representation of itself and then the representation setting response headers and body?</p>

<p>What would be your recommended approach? </p>
