本文整理汇总了PHP中FWValidator::is_serialized方法的典型用法代码示例。如果您正苦于以下问题:PHP FWValidator::is_serialized方法的具体用法?PHP FWValidator::is_serialized怎么用?PHP FWValidator::is_serialized使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FWValidator
的用法示例。
在下文中一共展示了FWValidator::is_serialized方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: export
/**
* This function is used to convert the array into entity objects.
*
* @param array $data
*
* @return array return as entity object array
*/
public function export($data)
{
if (empty($data)) {
return;
}
$em = \Env::get('em');
$entityClassMetaData = $em->getClassMetadata($this->entityClass);
$repository = $em->getRepository($this->entityClass);
$entities = array();
foreach ($data as $entityArray) {
$entityObj = null;
$primaryKeyName = $entityClassMetaData->getSingleIdentifierFieldName();
if (!empty($entityArray[$primaryKeyName])) {
$entityObj = $repository->findOneBy(array($primaryKeyName => $entityArray[$primaryKeyName]));
}
if (!$entityObj) {
$entityObj = new $this->entityClass();
}
//get the association mappings
$associationMappings = $entityClassMetaData->getAssociationMappings();
//class methods
$classMethods = get_class_methods($entityObj);
foreach ($entityArray as $entityField => $entityValue) {
$associationObj = null;
if (!in_array('set' . ucfirst($entityField), $classMethods)) {
continue;
}
if ($entityClassMetaData->isSingleValuedAssociation($entityField)) {
$targetEntity = $associationMappings[$entityField]['targetEntity'];
$mappingEntityField = $em->getClassMetadata($targetEntity)->getSingleIdentifierFieldName();
//check the association entity
$mappingEntityValue = is_array($entityValue) ? isset($entityValue[$mappingEntityField]) ? $entityValue[$mappingEntityField] : 0 : $entityValue;
if (!\FWValidator::isEmpty($mappingEntityValue)) {
$associationObj = $em->getRepository($targetEntity)->findOneBy(array($mappingEntityField => $mappingEntityValue));
}
if (!$associationObj) {
$associationObj = new $targetEntity();
}
if (is_array($entityValue)) {
foreach ($entityValue as $method => $value) {
$associationObj->{'set' . ucfirst($method)}($value);
}
} else {
$entityObj->{'set' . ucfirst($entityField)}($associationObj);
}
$entityValue = $associationObj;
}
//checks if the string a serialized array
if (\FWValidator::is_serialized($entityValue)) {
$entityValue = unserialize($entityValue);
}
$entityObj->{'set' . ucfirst($entityField)}($entityValue);
}
$entities[] = $entityObj;
}
return $entities;
}