Initial Commit
This commit is contained in:
parent
93a0b9be02
commit
6e599b2c0c
99 changed files with 10836 additions and 4 deletions
60
src/FederationLib/Classes/Validate.php
Normal file
60
src/FederationLib/Classes/Validate.php
Normal file
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
namespace FederationLib\Classes;
|
||||
|
||||
use FederationLib\Enums\Standard\PeerType;
|
||||
use FederationLib\Enums\Standard\InternetPeerType;
|
||||
use FederationLib\Enums\Standard\PeerAssociationType;
|
||||
use FederationLib\Enums\Standard\UserPeerType;
|
||||
|
||||
class Validate
|
||||
{
|
||||
/**
|
||||
* Determines the entity type based on the entity type string.
|
||||
*
|
||||
* @param string $entity_type
|
||||
* @return string
|
||||
*/
|
||||
public static function getEntityType(string $entity_type): string
|
||||
{
|
||||
if(in_array($entity_type, InternetPeerType::ALL))
|
||||
{
|
||||
return PeerType::INTERNET;
|
||||
}
|
||||
|
||||
if(in_array($entity_type, UserPeerType::ALL))
|
||||
{
|
||||
return PeerType::USER;
|
||||
}
|
||||
|
||||
return PeerType::UNKNOWN;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the entity type is valid and supported.
|
||||
*
|
||||
* @param string $entity_type
|
||||
* @return bool
|
||||
*/
|
||||
public static function validateEntityType(string $entity_type): bool
|
||||
{
|
||||
if(self::getEntityType($entity_type) === PeerType::UNKNOWN)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the peer association type.
|
||||
*
|
||||
* @param string $type
|
||||
* @return bool
|
||||
*/
|
||||
public static function peerAssociationType(string $type): bool
|
||||
{
|
||||
if(in_array(strtolower($type), PeerAssociationType::ALL))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue