From 4f9cc89cb8cd3da20bfdfe161edf1a3b8a62e5a7 Mon Sep 17 00:00:00 2001 From: netkas Date: Tue, 25 Mar 2025 14:20:20 -0400 Subject: [PATCH] Add methods to retrieve and check existence of information fields in Peer --- src/Socialbox/Objects/Standard/Peer.php | 30 +++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/Socialbox/Objects/Standard/Peer.php b/src/Socialbox/Objects/Standard/Peer.php index 7c1f32a..c83b134 100644 --- a/src/Socialbox/Objects/Standard/Peer.php +++ b/src/Socialbox/Objects/Standard/Peer.php @@ -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. *