Added method \FederationLib\Classes > Validate > associationType()

Refactored \FederationLib\Classes > Validate
This commit is contained in:
Netkas 2023-06-21 15:46:28 -04:00
parent e6a869c216
commit a2f4b2b685
No known key found for this signature in database
GPG key ID: 5DAF58535614062B

View file

@ -5,7 +5,6 @@
use FederationLib\Enums\Standard\PeerType;
use FederationLib\Enums\Standard\InternetPeerType;
use FederationLib\Enums\Standard\PeerAssociationType;
use FederationLib\Enums\Standard\PermissionRole;
use FederationLib\Enums\Standard\UserPeerType;
use FederationLib\Exceptions\Standard\InvalidPeerMetadataException;
@ -40,10 +39,7 @@
*/
public static function validateEntityType(string $entity_type): bool
{
if(self::getEntityType($entity_type) === PeerType::UNKNOWN)
return false;
return true;
return self::getEntityType($entity_type) !== PeerType::UNKNOWN;
}
/**
@ -54,8 +50,10 @@
*/
public static function peerAssociationType(string $type): bool
{
if(in_array(strtolower($type), PeerAssociationType::ALL))
if (in_array(strtolower($type), PeerAssociationType::ALL))
{
return true;
}
return false;
}
@ -112,28 +110,43 @@
* @return void
* @throws InvalidPeerMetadataException
*/
public static function validateMetadata(array $data, array $required, array $optional): void
public static function metadata(array $data, array $required, array $optional): void
{
foreach ($required as $property => $type)
foreach($required as $property => $type)
{
if (!isset($data[$property]))
if(!isset($data[$property]))
{
throw new InvalidPeerMetadataException(sprintf('The property "%s" is required in the metadata', $property));
}
if (gettype($data[$property]) !== $type)
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)
foreach($optional as $property => $type)
{
if (isset($data[$property]) && gettype($data[$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;
}
}