Exemple #1
0
 /**
  * Write a complex property and associated attributes.
  * 
  * @param ResourceProperty $complexProperty complex property
  * 
  * @return void
  */
 private function _writeComplexProperty(ResourceProperty $complexProperty)
 {
     $this->_xmlWriter->startElement(ODataConstants::PROPERTY);
     $this->_xmlWriter->writeAttribute(ODataConstants::NAME, $complexProperty->getName());
     $this->_xmlWriter->writeAttribute(ODataConstants::TYPE1, $complexProperty->getResourceType()->getFullName());
     $this->_xmlWriter->writeAttribute(ODataConstants::NULLABLE, "false");
     $this->_xmlWriter->endElement();
 }
 /**
  * Writes a primitive value and related information to the given
  * ODataProperty instance.
  * 
  * @param mixed            &$primitiveValue   The primitive value to write.
  * @param ResourceProperty &$resourceProperty The metadata of the primitive
  *                                            property value.
  * @param ODataProperty    &$odataProperty    ODataProperty instance to which
  *                                            the primitive value and related
  *                                            information to write out.
  *
  * @throws ODataException If given value is not primitive.
  * 
  * @return void
  */
 private function _writePrimitiveValue(&$primitiveValue, ResourceProperty &$resourceProperty, ODataProperty &$odataProperty)
 {
     if (is_object($primitiveValue)) {
         //TODO ERROR: The property 'PropertyName'
         //is defined as primitive type but value is an object
     }
     $odataProperty->name = $resourceProperty->getName();
     $odataProperty->typeName = $resourceProperty->getInstanceType()->getFullTypeName();
     if (is_null($primitiveValue)) {
         $odataProperty->value = null;
     } else {
         $resourceType = $resourceProperty->getResourceType();
         $this->_primitiveToString($resourceType, $primitiveValue, $odataProperty->value);
     }
 }
 public function testResourceProperty()
 {
     $addressResType = new ResourceType(new \ReflectionClass('UnitTests\\POData\\Facets\\NorthWind1\\Address2'), ResourceTypeKind::COMPLEX, 'Address', 'Northwind');
     $booleanResourcetype = ResourceType::getPrimitiveResourceType(EdmPrimitiveType::BOOLEAN);
     $isPrimaryPrimProperty = new ResourceProperty('IsPrimary', null, ResourcePropertyKind::PRIMITIVE, $booleanResourcetype);
     $addressResType->addProperty($isPrimaryPrimProperty);
     try {
         $addressComplexProperty = new ResourceProperty('Address', null, ResourcePropertyKind::COMPLEX_TYPE | ResourcePropertyKind::KEY, $addressResType);
         $this->fail('An expected InvalidArgumentException for \'invalid ResourcePropertyKind\' has not been raised');
     } catch (\InvalidArgumentException $exception) {
         $this->assertStringEndsWith('not a valid ResourcePropertyKind enum value or valid combination of ResourcePropertyKind enum values', $exception->getMessage());
     }
     $stringResourceType = ResourceType::getPrimitiveResourceType(EdmPrimitiveType::STRING);
     try {
         $addressComplexProperty = new ResourceProperty('Address', null, ResourcePropertyKind::COMPLEX_TYPE, $stringResourceType);
         $this->fail('An expected InvalidArgumentException for \'Property and ResourceType kind mismatch\' has not been raised');
     } catch (\InvalidArgumentException $exception) {
         $this->assertStringStartsWith('The \'$kind\' parameter does not match with the type of the resource type', $exception->getMessage());
     }
     $customerResType = new ResourceType(new \ReflectionClass('UnitTests\\POData\\Facets\\NorthWind1\\Customer2'), ResourceTypeKind::ENTITY, 'Customer', 'Northwind');
     $stringResourceType = ResourceType::getPrimitiveResourceType(EdmPrimitiveType::STRING);
     $customerIDPrimProperty = new ResourceProperty('CustomerID', null, ResourcePropertyKind::PRIMITIVE | ResourcePropertyKind::KEY, $stringResourceType);
     $customerNamePrimProperty = new ResourceProperty('CustomerName', null, ResourcePropertyKind::PRIMITIVE, $stringResourceType);
     $intResourceType = ResourceType::getPrimitiveResourceType(EdmPrimitiveType::INT32);
     $ratingPrimProperty = new ResourceProperty('Rating', null, ResourcePropertyKind::PRIMITIVE, $intResourceType);
     $customerResType->addProperty($customerIDPrimProperty);
     $customerResType->addProperty($customerNamePrimProperty);
     $customerResType->addProperty($ratingPrimProperty);
     $this->assertTrue($customerIDPrimProperty->isKindOf(ResourcePropertyKind::KEY));
     $this->assertTrue($customerIDPrimProperty->isKindOf(ResourcePropertyKind::PRIMITIVE));
     $customerReferenceSetProperty = new ResourceProperty('Customers', null, ResourcePropertyKind::RESOURCESET_REFERENCE, $customerResType);
     $this->assertEquals($customerReferenceSetProperty->getName(), 'Customers');
     $this->assertEquals($customerReferenceSetProperty->getKind(), ResourcePropertyKind::RESOURCESET_REFERENCE);
     $this->assertEquals($customerReferenceSetProperty->getInstanceType() instanceof \ReflectionClass, true);
     $this->assertEquals($customerReferenceSetProperty->getResourceType()->getName(), 'Customer');
     $this->assertEquals($customerReferenceSetProperty->getTypeKind(), ResourceTypeKind::ENTITY);
     $this->assertFalse($customerReferenceSetProperty->isKindOf(ResourcePropertyKind::RESOURCE_REFERENCE));
 }
 /**
  * Gets the ResourceAssociationSet instance for the given source 
  * association end.
  * 
  * @param ResourceSet      $sourceResourceSet      Resource set 
  *                                                 of the source
  *                                                 association end
  * @param ResourceType     $sourceResourceType     Resource type of the source
  *                                                 association end
  * @param ResourceProperty $targetResourceProperty Resource property of 
  *                                                 the source
  *                                                 association end
  * 
  * @return ResourceAssociationSet
  */
 public function getResourceAssociationSet(ResourceSet $sourceResourceSet, ResourceType $sourceResourceType, ResourceProperty $targetResourceProperty)
 {
     //e.g.
     //ResourceSet => Representing 'Customers' entity set
     //ResourceType => Representing'Customer' entity type
     //ResourceProperty => Representing 'Orders' property
     //We have created ResourceAssoicationSet while adding
     //ResourceSetReference or ResourceReference
     //and kept in $this->associationSets
     //$metadata->addResourceSetReferenceProperty(
     //             $customersEntityType,
     //             'Orders',
     //             $ordersResourceSet
     //             );
     $targetResourceSet = $targetResourceProperty->getResourceType()->getCustomState();
     if (is_null($targetResourceSet)) {
         throw new InvalidOperationException('Failed to retrieve the custom state from ' . $targetResourceProperty->getResourceType()->getName());
     }
     //Customer_Orders_Orders, Order_Customer_Customers
     $key = $sourceResourceType->getName() . '_' . $targetResourceProperty->getName() . '_' . $targetResourceSet->getName();
     if (array_key_exists($key, $this->associationSets)) {
         return $this->associationSets[$key];
     }
     return null;
 }
 /**
  * Get the resource type of the property hold by this expression
  * 
  * @return ResourceType
  */
 public function getResourceType()
 {
     return $this->resourceProperty->getResourceType();
 }