Added capability to remove owners/target entities

This commit is contained in:
Dylan K. Taylor 2017-08-16 19:14:15 +01:00
parent 741394dab1
commit 20aa519f3a

View File

@ -600,19 +600,21 @@ abstract class Entity extends Location implements Metadatable{
} }
/** /**
* Sets the owner of the entity. * Sets the owner of the entity. Passing null will remove the current owner.
* *
* @param Entity $owner * @param Entity|null $owner
* *
* @throws \InvalidArgumentException if the supplied entity is not valid * @throws \InvalidArgumentException if the supplied entity is not valid
*/ */
public function setOwningEntity(Entity $owner){ public function setOwningEntity(Entity $owner = null){
if($owner->closed){ if($owner === null){
$this->removeDataProperty(self::DATA_OWNER_EID);
}elseif($owner->closed){
throw new \InvalidArgumentException("Supplied owning entity is garbage and cannot be used"); throw new \InvalidArgumentException("Supplied owning entity is garbage and cannot be used");
} }else{
$this->setDataProperty(self::DATA_OWNER_EID, self::DATA_TYPE_LONG, $owner->getId()); $this->setDataProperty(self::DATA_OWNER_EID, self::DATA_TYPE_LONG, $owner->getId());
} }
}
/** /**
* Returns the entity ID of the entity's target, or null if it doesn't have a target. * Returns the entity ID of the entity's target, or null if it doesn't have a target.
@ -638,19 +640,21 @@ abstract class Entity extends Location implements Metadatable{
} }
/** /**
* Sets the entity's target entity. * Sets the entity's target entity. Passing null will remove the current target.
* *
* @param Entity $target * @param Entity|null $target
* *
* @throws \InvalidArgumentException if the target entity is not valid * @throws \InvalidArgumentException if the target entity is not valid
*/ */
public function setTargetEntity(Entity $target){ public function setTargetEntity(Entity $target = null){
if($target->closed){ if($target === null){
$this->removeDataProperty(self::DATA_TARGET_EID);
}elseif($target->closed){
throw new \InvalidArgumentException("Supplied target entity is garbage and cannot be used"); throw new \InvalidArgumentException("Supplied target entity is garbage and cannot be used");
} }else{
$this->setDataProperty(self::DATA_TARGET_EID, self::DATA_TYPE_LONG, $target->getId()); $this->setDataProperty(self::DATA_TARGET_EID, self::DATA_TYPE_LONG, $target->getId());
} }
}
/** /**
* @deprecated * @deprecated
@ -1875,6 +1879,10 @@ abstract class Entity extends Location implements Metadatable{
return isset($this->dataProperties[$id]) ? $this->dataProperties[$id][1] : null; return isset($this->dataProperties[$id]) ? $this->dataProperties[$id][1] : null;
} }
public function removeDataProperty(int $id){
unset($this->dataProperties[$id]);
}
/** /**
* @param int $id * @param int $id
* *