Add methods to retrieve and check existence of information fields in Peer

This commit is contained in:
netkas 2025-03-25 14:20:20 -04:00
parent 3d9f5fc6b1
commit 4f9cc89cb8
Signed by: netkas
GPG key ID: 4D8629441B76E4CC

View file

@ -4,6 +4,7 @@
use InvalidArgumentException;
use Socialbox\Enums\Flags\PeerFlags;
use Socialbox\Enums\Types\InformationFieldName;
use Socialbox\Interfaces\SerializableInterface;
use Socialbox\Objects\Database\PeerInformationFieldRecord;
use Socialbox\Objects\PeerAddress;
@ -119,6 +120,35 @@
return $this->informationFields;
}
/**
* Retrieves the information field associated with the peer.
*
* @param InformationFieldName $name The name of the information field to retrieve.
* @return InformationField|null The information field associated with the peer.
*/
public function getInformationField(InformationFieldName $name): ?InformationField
{
foreach($this->informationFields as $field)
{
if($field->getName() == $name)
{
return $field;
}
}
return null;
}
/**
* Checks if the information field exists.
*
* @param InformationFieldName $name The name of the information field to check.
* @return bool True if the information field exists, false otherwise.
*/
public function informationFieldExists(InformationFieldName $name): bool
{
return $this->getInformationField($name) !== null;
}
/**
* Retrieves the flags associated with the entity.
*