42); } /** * Validates a client description based on certain criteria. * * @param string $description The client description to validate * @return bool Returns true if the client description is valid, false otherwise */ public static function clientDescription(string $description): bool { $length = strlen($description); return !($length < 3 || $length > 255); } /** * Validates if the given permission role is valid. * * @param string|int $role * @return bool */ public static function permissionRole(string|int $role): bool { return (int)$role >= 0 && (int)$role <= 5; } /** * Validates the given metadata for a peer. * * @param array $data * @param array $required * @param array $optional * @return void * @throws InvalidPeerMetadataException */ public static function metadata(array $data, array $required, array $optional): void { foreach($required as $property => $type) { if(!isset($data[$property])) { throw new InvalidPeerMetadataException(sprintf('The property "%s" is required in the metadata', $property)); } if(gettype($data[$property]) !== $type) { throw new InvalidPeerMetadataException(sprintf('The property "%s" must be a %s in metadata, got %s', $property, $type, Security::gettype($data[$property]))); } } foreach($optional as $property => $type) { if(isset($data[$property]) && gettype($data[$property]) !== $type) { throw new InvalidPeerMetadataException(sprintf('The property "%s" must be a %s in metadata, got %s', $property, $type, Security::gettype($data[$property]))); } } } /** * Validates if the given association type is valid. * * @param string $type * @return bool */ public static function associationType(string $type): bool { if(in_array($type, PeerAssociationType::ALL)) { return true; } return false; } }