. * * @author Amir Hossein Jafari * @copyright 2016-2023 Amir Hossein Jafari * @license https://opensource.org/licenses/AGPL-3.0 AGPLv3 * @link https://docs.madelineproto.xyz MadelineProto documentation */ namespace danog\MadelineProto\EventHandler; use AssertionError; use JsonSerializable; /** @internal */ enum Privacy implements JsonSerializable { /** Allow all contacts */ case AllowContacts; /** Allow all users */ case AllowAll; /** Disallow only contacts */ case DisallowContacts; /** Disallow all users */ case DisallowAll; case AllowCloseFriends; /** * * @throws AssertionError */ public static function fromRawPrivacy(array $privacies): array { $create = function (array $data): Privacy|AbstractPrivacy { $newName = \substr($data['_'], 12); foreach (Privacy::cases() as $case) { if (\in_array($newName, ['AllowUsers', 'DisallowUsers', 'AllowChatParticipants', 'DisallowChatParticipants',])) { return new $newName($data); } if ($case->name === $newName) { return $case; } } throw new AssertionError("Undefined case Privacy::".$data['_']); }; return \array_map(fn (array $privacy) => $create($privacy), $privacies); } /** @internal */ public function jsonSerialize(): string { return $this->name; } }