/** * 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); }
public function getProperties(Model $pModel) { $lReturn = null; if ($pModel instanceof LocalModel) { $lInstanceModels =& $this->mLocalTypes[$pModel->getMainModel()->getModelName()]; } else { $lInstanceModels =& $this->mInstanceModels; } if (is_null($this->mManifestParser) && is_object($lInstanceModels[$pModel->getModelName()]) && $lInstanceModels[$pModel->getModelName()]->isLoaded()) { $lReturn = array(self::PROPERTIES => $pModel->getProperties(), self::OBJECT_CLASS => $pModel->getObjectClass()); if ($pModel instanceof MainModel) { $lReturn[self::SERIALIZATION] = $pModel->getSerialization(); } } else { $lUnsetManifestParser = false; if (is_null($this->mManifestParser)) { $lUnsetManifestParser = true; $lManifestPath_afe = $lInstanceModels[$pModel->getModelName()][0]; $lManifestPath_ad = dirname($lManifestPath_afe); $lSerializationPath_afe = !is_null($lInstanceModels[$pModel->getModelName()][1]) ? $lInstanceModels[$pModel->getModelName()][1] : null; $this->mManifestParser = ManifestParser::getInstance($pModel, $lManifestPath_afe, $lSerializationPath_afe); $this->_addInstanceModel($pModel); $this->_buildLocalTypes($pModel, $lManifestPath_ad); } $lExtends = $this->mManifestParser->getExtends(); // TODO manage extends $lObjectClass = $this->mManifestParser->getObjectClass(); $lReturn = [self::PROPERTIES => array(), self::OBJECT_CLASS => $lObjectClass, self::PROPERTIES => $this->_buildProperties($pModel)]; if ($lUnsetManifestParser) { $this->mSerializationManifestParser = $this->mManifestParser->getSerializationManifestParser(); unset($this->mManifestParser); $this->mManifestParser = null; } } return $lReturn; }
protected function _toXmlId(Object $pObject, $pXmlNode, $pUseSerializationName, $pDateTimeZone, &$pMainForeignObjects = null) { $lId = parent::_toXmlId($pObject, $pXmlNode, $pUseSerializationName, $pMainForeignObjects); if (is_array($pMainForeignObjects) && !(array_key_exists($this->mModelName, $pMainForeignObjects) && array_key_exists($lId, $pMainForeignObjects[$this->mModelName]))) { $lXmlNode = new \SimpleXmlElement("<{$this->getModelName()}/>"); $this->_toXml($pObject, $lXmlNode, $pUseSerializationName, $pDateTimeZone, $pMainForeignObjects); $pMainForeignObjects[$this->mModelName][$lId] = $lXmlNode; } }
/** * transform an stdClass to an array which each stdclass or array values are transformed to string * @param \stdClass $pObject * @param Model $pModel * @param boolean $pUseSerializationName */ public function objectToSqlArrayString($pPhpObject, $pModel, $pUseSerializationName) { $lMapOfString = array(); foreach ($pModel->getProperties() as $lProperty) { $lPropertyName = $pUseSerializationName ? $lProperty->getSerializationName() : $lProperty->getName(); if (!$lProperty->isComposition() && isset($pPhpObject->{$lPropertyName})) { $lValue = $pPhpObject->{$lPropertyName}; if (is_object($lValue) || is_array($lValue)) { $lValue = json_encode($lValue); } $lMapOfString[$lPropertyName] = $lValue; } } return $lMapOfString; }