60 lines
No EOL
1.6 KiB
PHP
60 lines
No EOL
1.6 KiB
PHP
<?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;
|
|
}
|
|
} |