Add serialization methods to PeerFlags enum
This commit is contained in:
parent
44143cb8cd
commit
9a9cb3957b
1 changed files with 29 additions and 0 deletions
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Socialbox\Enums\Flags;
|
||||
|
||||
use Socialbox\Classes\Logger;
|
||||
|
||||
enum PeerFlags : string
|
||||
{
|
||||
// Administrative Flags
|
||||
|
@ -20,6 +22,33 @@ enum PeerFlags : string
|
|||
case VER_PHONE_CALL = 'VER_PHONE_CALL';
|
||||
case VER_SOLVE_IMAGE_CAPTCHA = 'VER_SOLVE_IMAGE_CAPTCHA';
|
||||
|
||||
/**
|
||||
* Converts an array of PeerFlags enums to a string representation
|
||||
*
|
||||
* @param PeerFlags[] $flags Array of PeerFlags enums
|
||||
* @return string Comma-separated string of flag values
|
||||
*/
|
||||
public static function toString(array $flags): string
|
||||
{
|
||||
return implode(',', array_map(fn(PeerFlags $flag) => $flag->value, $flags));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a string representation back to an array of PeerFlags enums
|
||||
*
|
||||
* @param string $flagString Comma-separated string of flag values
|
||||
* @return PeerFlags[] Array of PeerFlags enums
|
||||
*/
|
||||
public static function fromString(string $flagString): array
|
||||
{
|
||||
if (empty($flagString))
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
return array_map(fn(string $value) => PeerFlags::from(trim($value)), explode(',', $flagString));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the flag is public. Public flags can be seen by other peers.
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue