Exemplo n.º 1
0
 /**
  * Write primitive property facets. 
  * 
  * @param ResourceProperty $primitveProperty primitive property
  * 
  * @return nothing
  */
 private function _writePrimitivePropertyFacets(ResourceProperty $primitveProperty)
 {
     $nullable = true;
     if ($primitveProperty->isKindOf(ResourcePropertyKind::KEY)) {
         $nullable = false;
     }
     $this->_iOdataWriter->writeAttribute(ODataConstants::NULLABLE, $nullable ? "true" : "false");
 }
Exemplo n.º 2
0
 /**
  * Add a property belongs to this resource type instance
  *
  * @param ResourceProperty $property Property to add
  *
  * @throws InvalidOperationException
  * @return void
  */
 public function addProperty(ResourceProperty $property)
 {
     if ($this->_resourceTypeKind == ResourceTypeKind::PRIMITIVE) {
         throw new InvalidOperationException(Messages::resourceTypeNoAddPropertyForPrimitive());
     }
     $name = $property->getName();
     foreach (array_keys($this->_propertiesDeclaredOnThisType) as $propertyName) {
         if (strcasecmp($propertyName, $name) == 0) {
             throw new InvalidOperationException(Messages::resourceTypePropertyWithSameNameAlreadyExists($propertyName, $this->_name));
         }
     }
     if ($property->isKindOf(ResourcePropertyKind::KEY)) {
         if ($this->_resourceTypeKind != ResourceTypeKind::ENTITY) {
             throw new InvalidOperationException(Messages::resourceTypeKeyPropertiesOnlyOnEntityTypes());
         }
         if ($this->_baseType != null) {
             throw new InvalidOperationException(Messages::resourceTypeNoKeysInDerivedTypes());
         }
     }
     if ($property->isKindOf(ResourcePropertyKind::ETAG) && $this->_resourceTypeKind != ResourceTypeKind::ENTITY) {
         throw new InvalidOperationException(Messages::resourceTypeETagPropertiesOnlyOnEntityTypes());
     }
     //Check for Base class properties
     $this->_propertiesDeclaredOnThisType[$name] = $property;
     // Set $this->_allProperties to null, this is very important because the
     // first call to getAllProperties will initilaize $this->_allProperties,
     // further call to getAllProperties will not reinitialize _allProperties
     // so if addProperty is called after calling getAllProperties then the
     // property just added will not be reflected in $this->_allProperties
     unset($this->_allProperties);
     $this->_allProperties = array();
 }
Exemplo n.º 3
0
 public function testResourceProperty()
 {
     try {
         $addressResType = new ResourceType(new ReflectionClass('Address2'), ResourceTypeKind::COMPLEX, 'Address', 'Northwind');
         $booleanResourcetype = ResourceType::getPrimitiveResourceType(EdmPrimitiveType::BOOLEAN);
         $isPrimaryPrimProperty = new ResourceProperty('IsPrimary', null, ResourcePropertyKind::PRIMITIVE, $booleanResourcetype);
         $addressResType->addProperty($isPrimaryPrimProperty);
         $exceptionThrown = false;
         try {
             $addressComplexProperty = new ResourceProperty('Address', null, ResourcePropertyKind::COMPLEX_TYPE | ResourcePropertyKind::KEY, $addressResType);
         } catch (\InvalidArgumentException $exception) {
             $exceptionThrown = true;
             $this->AssertStringEndsWith('not a valid ResourcePropertyKind enum value or valid combination of ResourcePropertyKind enum values', $exception->getMessage());
         }
         if (!$exceptionThrown) {
             $this->fail('An expected InvalidArgumentException for \'invalid ResourcePropertyKind\' has not been raised');
         }
         $exceptionThrown = false;
         try {
             $stringResourceType = ResourceType::getPrimitiveResourceType(EdmPrimitiveType::STRING);
             $addressComplexProperty = new ResourceProperty('Address', null, ResourcePropertyKind::COMPLEX_TYPE, $stringResourceType);
         } catch (\InvalidArgumentException $exception) {
             $exceptionThrown = true;
             $this->AssertStringStartsWith('The \'$kind\' parameter does not match with the type of the resource type', $exception->getMessage());
         }
         if (!$exceptionThrown) {
             $this->fail('An expected InvalidArgumentException for \'Property and ResourceType kind mismatch\' has not been raised');
         }
         $customerResType = new ResourceType(new ReflectionClass('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));
     } catch (\Exception $exception) {
         $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
     }
 }