protected final function _setSerialization()
 {
     if (!$this->mSerializationInitialised) {
         $this->mSerialization = InstanceModel::getInstance()->getSerialization($this);
         $this->mSerializationInitialised = true;
     }
 }
 public final function __construct($pModelName, $lIsLoaded = true)
 {
     if ($pModelName instanceof Model || $pModelName instanceof ModelContainer) {
         $this->mModel = $pModelName;
     } else {
         $this->mModel = InstanceModel::getInstance()->getInstanceModel($pModelName);
     }
     $this->mIsLoaded = $lIsLoaded;
 }
 private function _buildSerialization($pSerializationNode)
 {
     $lType = (string) $pSerializationNode["type"];
     if (isset($pSerializationNode->{$lType})) {
         $lObjectXml = $pSerializationNode->{$lType};
         $lSerialization = InstanceModel::getInstance()->getInstanceModel($lType)->getObjectInstance();
         $lSerialization->fromXml($lObjectXml);
     } else {
         $lId = (string) $pSerializationNode;
         if (empty($lId)) {
             throw new \Exception('malformed serialization, must have description or id');
         }
         $lSerialization = InstanceModel::getInstance()->getInstanceModel($lType)->loadObject($lId);
     }
     return $lSerialization;
 }
 private function _buildSerialization($pSerializationNode)
 {
     $lType = $pSerializationNode['type'];
     if (isset($pSerializationNode['value'])) {
         $lSerialization = InstanceModel::getInstance()->getInstanceModel($lType)->getObjectInstance();
         $lSerialization->fromObject($pSerializationNode['value']);
     } else {
         if (isset($pSerializationNode['id'])) {
             $lId = $pSerializationNode['id'];
             if (empty($lId)) {
                 throw new \Exception('malformed serialization, must have description or id');
             }
             $lSerialization = InstanceModel::getInstance()->getInstanceModel($lType)->loadObject($lId);
         } else {
             throw new \Exception('malformed serialization');
         }
     }
     return $lSerialization;
 }
 /**
  * don't instanciate a model by yourself because it take time
  * to get a model instance use singleton InstanceModel
  */
 public function __construct($pModelName, $pMainModelName, $pLoadModel)
 {
     $this->mMainModel = InstanceModel::getInstance()->getInstanceModel($pMainModelName);
     parent::__construct($pModelName, $pLoadModel);
 }
    throw new Exception('model \'sqlDatabase\' not initialized');
}
if (!InstanceModel::getInstance()->isModelLoaded('sqlDatabase')) {
    throw new Exception('model must be loaded');
}
/** ****************************** same serialization object and model instance ****************************** **/
if ($lPlaceModel->getSerialization()->getValue('database') !== $lTestDbModel->getSerialization()->getValue('database')) {
    throw new Exception('models haven\'t same serialization');
}
if ($lPlaceModel->getSerialization()->getModel() !== $lTestDbModel->getSerialization()->getModel()) {
    throw new Exception('models haven\'t same instance');
}
if (InstanceModel::getInstance()->getInstanceModel('sqlDatabase') !== $lTestDbModel->getSerialization()->getValue('database')->getModel()) {
    throw new Exception('models haven\'t same instance');
}
if (InstanceModel::getInstance()->getInstanceModel('sqlTable') !== $lTestDbModel->getSerialization()->getModel()) {
    throw new Exception('models haven\'t same instance');
}
$lObj = $lTestModel->getObjectInstance();
$lModelArray = new ModelArray($lTestModel, 'sesreer');
$lObjArray = $lModelArray->getObjectInstance();
$lObjValue = $lObj->getproperty('objectValue')->getModel()->getObjectInstance();
$lObj->setValue('name', 'sddsdfffff');
$lObj->setValue('objectValue', $lObjValue);
$lObj->setValue('objectValues', $lObjArray);
$lObj->setValue('foreignObjectValues', $lObjArray);
if (!InstanceModel::getInstance()->hasInstanceModel('sqlTable')) {
    throw new Exception('model already initialized');
}
$time_end = microtime(true);
var_dump('model test exec time ' . ($time_end - $time_start));
 public function __construct($pModelName)
 {
     $this->mModel = InstanceModel::getInstance()->getInstanceModel($pModelName);
 }
<?php

set_include_path(get_include_path() . PATH_SEPARATOR . '/home/jean-philippe/public_html/ObjectManagerLib');
require_once 'Comhon.php';
use comhon\object\singleton\InstanceModel;
$lTestXmlModel = InstanceModel::getInstance()->getInstanceModel('testXml');
$lTestXml = $lTestXmlModel->loadObject('plop2');
$lTestXml->setValue('name', 'plop4');
$lTestXml->save();
 private function _getModelLiterals($pPhpObjectLogicalJunction, $pMainTableName, &$pModels)
 {
     if (isset($pPhpObjectLogicalJunction->literals)) {
         foreach ($pPhpObjectLogicalJunction->literals as $lLiteral) {
             if (!isset($lLiteral->model)) {
                 throw new \Exception("malformed phpObject literal : " . json_encode($lLiteral));
             }
             InstanceModel::getInstance()->getInstanceModel($lLiteral->model);
             // verify if model exists
             if (!array_key_exists($lLiteral->model, $pModels)) {
                 $pModels[$lLiteral->model] = array();
             }
             if ($lLiteral->model == $this->mModel->getModelName()) {
                 $lLiteral->node = $pMainTableName;
             } else {
                 $pModels[$lLiteral->model][] = $lLiteral;
             }
             unset($lLiteral->model);
         }
     }
     if (isset($pPhpObjectLogicalJunction->logicalJunctions)) {
         foreach ($pPhpObjectLogicalJunction->logicalJunctions as $lLogicalJunction) {
             $this->_getModelLiterals($lLogicalJunction, $pMainTableName, $pModels);
         }
     }
 }
    throw new Exception('bad objects : ' . json_encode($lResult->result));
}
/** ****************************** test following export import objects ****************************** **/
$lBasedObjects = [json_decode('{"id1":"1","id2":"23","date":"2016-05-01T14:53:54+02:00","timestamp":"2016-10-16T21:50:19+02:00","string":"aaaa","integer":0,"mainParentTestDb":"1"}'), json_decode('{"id1":"1","id2":"101","date":"2016-04-13T09:14:33+02:00","timestamp":"2016-10-16T21:50:19+02:00","string":"cccc","integer":2,"object":{"plop":"plop","plop2":"plop2"},"objectWithId":{"plop":"plop","plop2":"plop2"},"mainParentTestDb":"1"}')];
$lObject = null;
foreach ($lResult->result as $lIndex => $lPhpObject) {
    $lObject = new Object('testDb');
    $lObject->fromObject($lPhpObject);
    $lObject2 = new Object('testDb');
    $lObject2->fromXml($lObject->toXml(false));
    if (json_encode($lObject2->toObject(false, 'Europe/Berlin')) !== json_encode($lBasedObjects[$lIndex])) {
        throw new Exception('bad object : ' . json_encode($lObject2->toObject(false, 'Europe/Berlin')));
    }
}
/** ****************************** test DateTime/DateTimeZone with database serialization ****************************** **/
$lDbTestModel = InstanceModel::getInstance()->getInstanceModel('testDb');
$lObject = $lDbTestModel->loadObject('[1,1501774389]');
$lObjectJson = $lObject->toObject();
$lObject->getValue('timestamp')->sub(new DateInterval('P0Y0M0DT5H0M0S'));
$lObject->save(SqlTable::UPDATE);
$lObject = $lDbTestModel->loadObject('[1,1501774389]', true);
$lObject->getValue('timestamp')->add(new DateInterval('P0Y0M0DT5H0M0S'));
$lObject->save(SqlTable::UPDATE);
$lObject = $lDbTestModel->loadObject('[1,1501774389]', true);
if (json_encode($lObject->toObject()) !== json_encode($lObjectJson)) {
    throw new Exception('bad object');
}
/** ****************************** test simple load request api ****************************** **/
$lParams = new stdClass();
$lParams->model = 'testDb';
$lParams->id = '[1,1501774389]';
 protected function _toSqlDataBase(Object $pObject, $pUseSerializationName, $pDateTimeZone, &$pMainForeignObjects = null)
 {
     $lPhpObject = $this->_toObject($pObject, $pUseSerializationName, $pDateTimeZone, $pMainForeignObjects);
     $lMapOfString = $this->objectToSqlArrayString($lPhpObject, $this, $pUseSerializationName);
     if (is_array($pMainForeignObjects)) {
         foreach ($pMainForeignObjects as $lMainModelName => &$lValues) {
             $lModel = InstanceModel::getInstance()->getInstanceModel($lMainModelName);
             foreach ($pMainForeignObjects as $lId => $lValue) {
                 $lValues[$lId] = $this->objectToSqlArrayString($lPhpObject, $lModel, $pUseSerializationName);
             }
         }
     }
     return $lMapOfString;
 }