예제 #1
0
 /**
  * To add a navigation property (resource set or resource reference)
  * to a resource type
  * 
  * @param ResourceType         $resourceType         The resource type to add 
  *                                                   the resource reference 
  *                                                   or resource 
  *                                                   reference set property to
  * @param string               $name                 The name of the 
  *                                                   property to add
  * @param ResourceSet          $targetResourceSet    The resource set the 
  *                                                   resource reference
  *                                                   or reference 
  *                                                   set property 
  *                                                   ponits to
  * @param ResourcePropertyKind $resourcePropertyKind The property kind
  * 
  * @return void
  */
 private function _addReferencePropertyInternal(ResourceType $resourceType, $name, ResourceSet $targetResourceSet, $resourcePropertyKind)
 {
     try {
         $resourceType->getInstanceType()->getProperty($name);
     } catch (ReflectionException $exception) {
         throw new InvalidOperationException('Can\'t add a property which does not exist on the instance type.');
     }
     if (!($resourcePropertyKind == ResourcePropertyKind::RESOURCESET_REFERENCE || $resourcePropertyKind == ResourcePropertyKind::RESOURCE_REFERENCE)) {
         throw new InvalidOperationException('Property kind should be ResourceSetReference or ResourceReference');
     }
     $targetResourceType = $targetResourceSet->getResourceType();
     $resourceProperty = new ResourceProperty($name, null, $resourcePropertyKind, $targetResourceType);
     $resourceType->addProperty($resourceProperty);
     //Create instance of AssociationSet for this relationship
     $sourceResourceSet = $resourceType->getCustomState();
     if (is_null($sourceResourceSet)) {
         throw new InvalidOperationException('Failed to retrieve the custom state from ' . $resourceType->getName());
     }
     //Customer_Orders_Orders, Order_Customer_Customers
     //(source type::name _ source property::name _ target set::name)
     $assoicationSetKey = $resourceType->getName() . '_' . $name . '_' . $targetResourceSet->getName();
     $associationSet = new ResourceAssociationSet($assoicationSetKey, new ResourceAssociationSetEnd($sourceResourceSet, $resourceType, $resourceProperty), new ResourceAssociationSetEnd($targetResourceSet, $targetResourceSet->getResourceType(), null));
     $this->associationSets[$assoicationSetKey] = $associationSet;
 }