Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6713421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:22:43+00:00 2026-05-26T08:22:43+00:00

I am currently in the process of developing an open source RMR framework. At

  • 0

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):

/**
 * 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->getMethod());
    $this->dataSource = $dataSource;
    $this->parameters = $parameters;
    $this->request = $request;

    if(method_exists($this, $method))
    {
        // Something like get, post, head in resources
        $data = $this->$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->getMediaType();

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

        return $response;
    }
    else
    {
        return new Response(StatusCode::HTTP_METHOD_NOT_ALLOWED);
    }
}

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?

What would be your recommended approach?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:22:44+00:00Added an answer on May 26, 2026 at 8:22 am

    Leave that to a RepresentationResolver which operates on Request, Response and Resource. Keep classes small and distinct.

    interface RepresentationResolver
    {
        /**
         * @return Representation
         */
        public function resolve();
    }
    
    class DataRepresentationResolver implements RepresentationResolver
    {
        public function __construct(your arguments)
        {
    
        }
        public function resolve()
        {
            ...
            $representation = $this->getRepresentation($this->data);
        }
    }
    

    Then when you compile the response:

    $resolver = new DataRepresentationResolver(your arguments);
    $representation = $resolver->resolve();
    $representation->parse($response, $data);
    

    You can then code any type or RepresentationResolver you see fit, even families of such, e.g. working with a specific request type or for specific sort of media type you specify (e.g. by mime-type).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently in the process of developing a digg-like Ruby on Rails application for
I am developing web application using Yii framework. currently i am in the process
I'm currently in the process of developing a GWT 1.7.1 application that deals with
We're currently in the process of setting up a source control/build/and more-server for .NET
I'm currently in the process of developing a fairly large static library which will
I’m currently in the process of developing my own blogging system. Currently when you
This is somewhat of an open question. I'm in the process of developing a
I'm currently in the process of developing an app for the iPhone. There is
I'm currently in the process of developing an app which has some very demanding
Greetings, Currently I am in process of developing an application for booking (etc. rooms).

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.