PocketMine-MP
5.32.2 git-237b304ef9858756b018e44e8f298093f66f823b
Loading...
Searching...
No Matches
StringEnumMap.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
22
declare(strict_types=1);
23
24
namespace
pocketmine\data\bedrock\block\convert;
25
26
use
pocketmine\data\bedrock\block\BlockStateDeserializeException
;
27
use
function
spl_object_id;
28
32
class
StringEnumMap
{
37
private
array $enumToValue = [];
38
43
private
array $valueToEnum = [];
44
49
public
function
__construct
(
50
private
string
$class,
51
\Closure $mapper
52
){
53
foreach
($class::cases() as $case){
54
$string = $mapper($case);
55
$this->valueToEnum[$string] = $case;
56
$this->
enumToValue
[spl_object_id($case)] = $string;
57
}
58
}
59
63
public
function
enumToValue
(\UnitEnum $enum) : string{
64
return $this->
enumToValue
[spl_object_id($enum)];
65
}
66
67
public
function
valueToEnum(
string
$string) : ?\UnitEnum{
68
return $this->valueToEnum[$string] ?? throw new
BlockStateDeserializeException
(
"No $this->class enum mapping for \"$string\""
);
69
}
70
75
public
function
getValueToEnum
() : array{
76
return $this->valueToEnum;
77
}
78
}
pocketmine\data\bedrock\block\BlockStateDeserializeException
Definition
BlockStateDeserializeException.php:26
pocketmine\data\bedrock\block\convert\StringEnumMap
Definition
StringEnumMap.php:32
pocketmine\data\bedrock\block\convert\StringEnumMap\__construct
__construct(private string $class, \Closure $mapper)
Definition
StringEnumMap.php:49
pocketmine\data\bedrock\block\convert\StringEnumMap\getValueToEnum
getValueToEnum()
Definition
StringEnumMap.php:75
pocketmine\data\bedrock\block\convert\StringEnumMap\enumToValue
enumToValue(\UnitEnum $enum)
Definition
StringEnumMap.php:63
src
data
bedrock
block
convert
StringEnumMap.php
Generated by
1.12.0