Ejemplo n.º 1
0
 /**
  *
  * @param ClientType::Property $property
  * @param Object $object reference to the complex property of entity
  */
 protected function CheckAndCreateChangeSetBodyPartForComplexType($property, $object)
 {
     $propertyNameCT = $property->getName();
     $propertyAttributes = $property->getAttributes();
     $complexBody = null;
     $index = 0;
     //Now check for complex type. If type not start with 'Edm.'
     //it can be a complex type.
     if (isset($propertyAttributes['EdmType']) && ($index = strpos($propertyAttributes['EdmType'], 'Edm.')) !== 0) {
         $complexBody = '<d:' . $propertyNameCT . ' m:type="' . $propertyAttributes['EdmType'] . '">' . "\n";
         $type = ClientType::Create($propertyNameCT);
         $nonEpmProperties = $type->getRawNonEPMProperties(true);
         foreach ($nonEpmProperties as $nonEpmProperty) {
             $propertyName = $nonEpmProperty->getName();
             $refProperty = new ReflectionProperty($object, $propertyName);
             $propertyValue = $refProperty->getValue($object);
             $property = '';
             // determine if the property is null and should be output accordingly
             // for numeric types, utilize a numeric value
             if (!$propertyValue) {
                 Utility::GetPropertyType($refProperty, $notNullable);
                 if (!$notNullable) {
                     $property = "<d:" . $propertyName . " " . "m:null=\"true\" />";
                 } elseif (strpos($edmType, 'Edm.Decimal') === 0) {
                     $property = '<d:' . $propertyName . '>0.0M</d:' . $propertyName . '>';
                 } elseif (strpos($edmType, 'Edm.Double') === 0) {
                     $property = '<d:' . $propertyName . '>0.0</d:' . $propertyName . '>';
                 } elseif (strpos($edmType, 'Edm.Int') === 0) {
                     $property = '<d:' . $propertyName . '>0</d:' . $propertyName . '>';
                 } elseif (strpos($edmType, 'Edm.Single') === 0) {
                     $property = '<d:' . $propertyName . '>0.0f</d:' . $propertyName . '>';
                 } else {
                     continue;
                 }
             } else {
                 $attributes = $nonEpmProperty->getAttributes();
                 $edmType = '';
                 if (isset($attributes['EdmType']) && $attributes['EdmType'] != 'Edm.String') {
                     $edmType = ' m:type="' . $attributes['EdmType'] . '"';
                     // wrap value in CDATA tag since strings may contain XML special characters
                     $propertyValue = "<![CDATA[" . $propertyValue . "]]>";
                 }
                 $property = '<d:' . $propertyName . $edmType . '>' . $propertyValue . '</d:' . $propertyName . '>';
             }
             if (isset($property)) {
                 Utility::WriteLine($complexBody, $property);
             }
         }
     }
     if ($complexBody) {
         $complexBody .= '</d:' . $propertyNameCT . '>';
     }
     return $complexBody;
 }
Ejemplo n.º 2
0
 /**
  *
  * @param ClientType::Property $property
  * @param Object $object reference to the complex property of entity
  */
 protected function CheckAndCreateChangeSetBodyPartForComplexType($property, $object)
 {
     $propertyNameCT = $property->getName();
     $propertyAttributes = $property->getAttributes();
     $complexBody = null;
     $index = 0;
     //Now check for complex type. If type not start with 'Edm.'
     //it can be a complex type.
     if (isset($propertyAttributes['EdmType']) && ($index = strpos($propertyAttributes['EdmType'], 'Edm.')) !== 0) {
         $complexBody = '<d:' . $propertyNameCT . ' m:type="' . $propertyAttributes['EdmType'] . '">' . "\n";
         $type = ClientType::Create($propertyNameCT);
         $nonEpmProperties = $type->getRawNonEPMProperties(true);
         foreach ($nonEpmProperties as $nonEpmProperty) {
             $propertyName = $nonEpmProperty->getName();
             $refProperty = new ReflectionProperty($object, $propertyName);
             $propertyValue = $refProperty->getValue($object);
             $property = null;
             if (empty($propertyValue) || is_null($propertyValue)) {
                 Utility::GetPropertyType($refProperty, $notNullable);
                 if (!$notNullable) {
                     $property = "<d:" . $propertyName . " " . "m:null=\"true\" />";
                 } else {
                     continue;
                 }
             } else {
                 $attributes = $nonEpmProperty->getAttributes();
                 $edmType = '';
                 if (isset($attributes['EdmType']) && $attributes['EdmType'] != 'Edm.String') {
                     $edmType = ' m:type="' . $attributes['EdmType'] . '"';
                 }
                 $property = '<d:' . $propertyName . "{$edmType}>" . $propertyValue . '</d:' . $propertyName . '>';
             }
             if (isset($property)) {
                 Utility::WriteLine($complexBody, $property);
             }
         }
     }
     if ($complexBody) {
         $complexBody .= '</d:' . $propertyNameCT . '>';
     }
     return $complexBody;
 }