Cleanup
This commit is contained in:
parent
0a8f7589b9
commit
1728d607d7
16 changed files with 71 additions and 152 deletions
|
@ -7,6 +7,7 @@
|
|||
use FederationLib\Enums\Standard\PeerAssociationType;
|
||||
use FederationLib\Enums\Standard\PermissionRole;
|
||||
use FederationLib\Enums\Standard\UserPeerType;
|
||||
use FederationLib\Exceptions\Standard\InvalidPeerMetadataException;
|
||||
|
||||
class Validate
|
||||
{
|
||||
|
@ -102,4 +103,37 @@
|
|||
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 validateMetadata(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])));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue