/** * Add a property * * @param Property $property * @param bool $overwrite * @return self * @throws Exception\DomainException */ public function add(Property $property, $overwrite = false) { $keyword = $property->getKeyword(); if (!isset($this->properties[$keyword]) || $overwrite || 'id' == $keyword) { $this->properties[$keyword] = $property; return $this; } if ($this->properties[$keyword] instanceof Property || $this->properties[$keyword] instanceof PropertyCollection) { $this->properties[$keyword] = [$this->properties[$keyword]]; } if (!is_array($this->properties[$keyword])) { $type = is_object($this->properties[$keyword]) ? get_class($this->properties[$keyword]) : gettype($this->properties[$keyword]); throw new Exception\DomainException(sprintf('%s::$properties should be either a %s\\Property or an array; however, it is a "%s"', __CLASS__, __NAMESPACE__, $type)); } $this->properties[$keyword][] = $property; return $this; }
public function testConstructorTakesPropertyRelationName() { $property = new Property('describedby'); $this->assertEquals('describedby', $property->getKeyword()); }