Ejemplo n.º 1
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();
 }