[TYPO3-mvc] Mapping various Objects to a Domain Model

Thomas "Thasmo" Deinhamer thasmo at gmail.com
Fri Jun 15 00:13:44 CEST 2012


Hello Henjo,

I got several models of type "Server" and those
share common properties like "status" or "os" etc.

class Tx_MyExt_Domain_Model_Server_NewServer
extends Tx_MyExt_Domain_Model_Server;

class Tx_MyExt_Domain_Model_Server_SimpleServer
extends Tx_MyExt_Domain_Model_Server;

class Tx_MyExt_Domain_Model_Server_AwesomeServer
extends Tx_MyExt_Domain_Model_Server;

Now the raw data, which holds the original metadata
for each server, is JSON and every JSON object looks
different among the various servers.

NewServer:
{status: 1, os: "Linux"}

SimpleServer:
{running: "yes", operatingSystem: "Windows"}

AwesomeServer:
{offline: FALSE}
// No OS set, but we know "AwesomeServer" runs "Ubuntu".

The Server Model looks like this:

class Tx_MyExt_Domain_Model_Server {

   /**
    * @var boolean
    */
   protected $status;

   /**
    * @var integer
    */
   protected $operatingSystem;

   // ...
}

Now I get this raw JSON objects from a web service
and I want to have some kind of helper object or
helper functions which map/convert/populate those
JSON objects to my domain models.

I want to encapsulate this conversion/mapping inside
a class/several classes/methods/files.

Actually this is my question. What is the best solution
to convert/map those JSON data to my models in a flexible,
extendable, easy to maintain way?

Thanks a lot,
Thomas

Henjo Hoeksma schrieb:
> aren't you just trying to add objects to the server object? If it is
> attached the value is true, if not it isn't?


More information about the TYPO3-project-typo3v4mvc mailing list