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

  • Home
  • SEARCH
  • 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 8433449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:23:20+00:00 2026-06-10T06:23:20+00:00

Update: Ok some update, finally we have decided on the framework (Yii) and have

  • 0

Update:

Ok some update, finally we have decided on the framework (Yii) and have some initial structures. I will paste some of the relavent code to illustrate our current status:
(only has read action here)

Controller

class SponsorController extends RestController
{
    public function actionRestView($id)
    {
        $sponsorMapper = new SponsorMapper(
            new Db1Adapter(), // Gateway to the external SOAP Webservice
            new Db2Adapter()  // Gateway to the external REST Webservice
        );

        $data = $sponsorMapper->read($id);

        $this->renderJson(
            array(
                'success' => true,
                'message' => 'Record Retrieved Successfully',
                'data' => $data
            )
        );
    }
}

Domain Model

class Sponsor extends CModel
{
    public $id;
    public $db1Result;
    public $db2Result;

    public function attributeNames()
    {
        return array(
            'id',
            'db1Result',
            'db2Result',
        );
    }
}

Data Mapper

class SponsorMapper extends Mapper
{
    public function __construct(SoapAdapter $db1Adapter,
                                RestAdapter $db2Adapter)
    {
        $this->adapters['soap'] = $db1Adapter;
        $this->adapters['rest'] = $db2Adapter;
    }

    public function read($id)
    {
        $db1Result = $this->adapters['soap']->demoRequest();
        $db2Result = $this->adapters['rest']->demoRequest();

        return $this->createEntity($db1Result, $db2Result);
    }

    protected function createEntity($db1Result, $db2Result)
    {
        $sponsor = new Sponsor();
        $sponsor->db1Result = $db1Result;
        $sponsor->db2Result = $db2Result;

        return $sponsor;
    }
}

Now I have 2 questions:

  1. Right now the property of Sponsor object is just db1Result and db2Result and I will change it to the actual properties (eg. firstName, lastName, email) so the SponsorMapper::createEntity will be something like this:

    protected function createEntity($db1Result, $db2Result)
    {
        $sponsor = new Sponsor();
        $sponsor->firstName = $db1Result->result->first_name;
        $sponsor->lastName = $db1Result->result->last_name;
        $sponsor->email = $db2Result->QueryResult->ItemObject->email;
    
        return $sponsor;
    }
    

It seems to me that these kinds of stuff should happen inside the domain object instead mapper; I know I can treat db1Result and db2Result as domain object of their own and create their relations to Sponsor domain object, but I’m not sure if that’s the right direction. Should I do it in the mapper?

  1. I will need introduce a caching layer because to retrieve data from external databases is not fast. Where is the best place/practice to introduce caching layer? One way to do it is in the controller, so code caching layer as another mapper, and if this cache mapper doesn’t return data, we can then go the long way to retrive stuff from external. But this solution means I will need to put all those logics all over the controller actions, maybe there is a better way to place caching layer?

Initial Question:

We are in the process of designing/creating a RESTFul API project on top of PHP MVC framework. The project’s goal is to serve as an adapter between two other “foreign” APIs (one SOAP, the other REST).

I’m thinking the models in this project should roughly work like this:

  • Say we have a collection of user data on both “foreign” database
    behind their respective APIs, and locally we create a model “User”
  • Say we have a “GetById” method inside the “User” model, which needs
    to: grab the user data by id from both foreign APIs, combine and
    return the result.
  • I probably will use a builder pattern inside “User” model to
    instantiate 2 other models (for each foreign API), and ask those 2
    models to fetch data. With this structure I can let the 2 additional
    models to inherit things need for them to communicate with their
    APIs.
  • So we have those models:

    1. User
    2. SOAPBuilder
    3. RESTBuilder
    4. UserSOAP
    5. UserREST

Now what I don’t like about this design is, the structure is a bit complex and I don’t know a good way to place those model files into different places based on their “types” (the User model itself, the builder models, etc).

Am I over-designing this? Is there better patterns I should consider?

  • 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-06-10T06:23:22+00:00Added an answer on June 10, 2026 at 6:23 am

    There are no “multiple models” in MVC. Model is one of two layers (along with presentation layer), which make up the MVC design pattern. What people usually call “models” are actually domain objects. You might find this relevant.

    That said, you are looking at this all the wrong way. What you currently have is variation of active record pattern. Only, instead of database, in this case storage medium is REST API and/or SOAP interface instead of classical SQL storage.

    The best option in this case would be to separate the domain object (for example: User) from the different elements of storage related logic. I personally prefer to implement data mappers for this. Essentially, if you have a domain object, you pass it to the mapper’s method, which then either retrieves information from said object and sends it to storage or retrieves the data from storage and applies it to that domain object.

    The User instance does not care whether it was save or not. It has no impact on domain logic.

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

Sidebar

Related Questions

I've been doing some research into finally automating our Development builds and still have
I'm trying to update some properties with KVC. The properties have been synthesized. This
I am trying to update some hibernate code that was written by someone else
I'm using GNAT Programming Studio to update some ada files. I have a style
Common situation: I have a client on my server who may update some of
I have some old C# plugin code that was implemented strictly with Reflection. In
I'm trying to update the display brightness from a widget but i have some
I finally got some understanding of how Ninject handles DI, but have faced the
I have some code here: (...) NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; if(
I want to update some file in a server, with an automated script and

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.