PocketMine-MP 5.23.3 git-f7687af337d001ddbcc47b8e773f014a33faa662
Loading...
Searching...
No Matches
EnumTrait.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\utils;
25
37 use RegistryTrait;
38 use NotCloneable;
39 use NotSerializable;
40
46 protected static function register(self $member) : void{
47 self::_registryRegister($member->name(), $member);
48 }
49
50 protected static function registerAll(self ...$members) : void{
51 foreach($members as $member){
52 self::register($member);
53 }
54 }
55
63 public static function getAll() : array{
64 //phpstan doesn't support generic traits yet :(
66 $result = self::_registryGetAll();
67 return $result;
68 }
69
71 private static $nextId = null;
72
74 private $enumName;
76 private $runtimeId;
77
81 private function __construct(string $enumName){
82 self::verifyName($enumName);
83 $this->enumName = $enumName;
84 if(self::$nextId === null){
85 self::$nextId = Process::pid(); //this provides enough base entropy to prevent hardcoding
86 }
87 $this->runtimeId = self::$nextId++;
88 }
89
90 public function name() : string{
91 return $this->enumName;
92 }
93
99 public function id() : int{
100 return $this->runtimeId;
101 }
102
106 public function equals(self $other) : bool{
107 return $this->enumName === $other->enumName;
108 }
109}
static register(self $member)
Definition EnumTrait.php:46
equals(self $other)
static getAll()
Definition EnumTrait.php:63