當前位置: 首頁>>代碼示例>>PHP>>正文


PHP FWValidator::is_serialized方法代碼示例

本文整理匯總了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;
 }
開發者ID:nahakiole,項目名稱:cloudrexx,代碼行數:64,代碼來源:EntityInterface.class.php


注:本文中的FWValidator::is_serialized方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。