/** * 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; }
private function _getOrderResourceType() { $orderResType = new ResourceType(new ReflectionClass('Order2'), ResourceTypeKind::ENTITY, 'Order', 'Northwind'); $intResourceType = ResourceType::getPrimitiveResourceType(EdmPrimitiveType::INT32); $orderIDPrimProperty = new ResourceProperty('OrderID', null, ResourcePropertyKind::PRIMITIVE | ResourcePropertyKind::KEY, $intResourceType); $dateTimeResourceType = ResourceType::getPrimitiveResourceType(EdmPrimitiveType::DATETIME); $orderDatePrimProperty = new ResourceProperty('OrderDate', null, ResourcePropertyKind::PRIMITIVE, $dateTimeResourceType); $stringResourceType = ResourceType::getPrimitiveResourceType(EdmPrimitiveType::STRING); $orderShipNamePrimProperty = new ResourceProperty('ShipName', null, ResourcePropertyKind::PRIMITIVE, $stringResourceType); $orderResType->addProperty($orderIDPrimProperty); $orderResType->addProperty($orderDatePrimProperty); $orderResType->addProperty($orderShipNamePrimProperty); return $orderResType; }