| @@ 33-44 (lines=12) @@ | ||
| 30 | * @param int $values A number representing a bit mask |
|
| 31 | * @return ISet |
|
| 32 | */ |
|
| 33 | public function convertToEnumSet($values) : ISet |
|
| 34 | { |
|
| 35 | $bitValue = (int) $values; |
|
| 36 | ||
| 37 | $set = []; |
|
| 38 | foreach ($this->mapping as $value => $bit) { |
|
| 39 | if ($bitValue & $bit) { |
|
| 40 | $set[] = call_user_func([$this->enumClass, 'instance'], $value); |
|
| 41 | } |
|
| 42 | } |
|
| 43 | return new ImmutableSet($this->enumClass, $set); |
|
| 44 | } |
|
| 45 | ||
| 46 | public function convertFromEnumSet(ISet $enumSet): int |
|
| 47 | { |
|
| @@ 33-43 (lines=11) @@ | ||
| 30 | * @param string $serialized |
|
| 31 | * @return ImmutableSet |
|
| 32 | */ |
|
| 33 | public function convertToEnumSet($serialized): ISet |
|
| 34 | { |
|
| 35 | $serialized = (string) $serialized; |
|
| 36 | $stringList = unserialize($serialized); |
|
| 37 | ||
| 38 | $set = []; |
|
| 39 | foreach ($stringList as $value) { |
|
| 40 | $set[] = call_user_func([$this->enumClass, 'instance'], $value); |
|
| 41 | } |
|
| 42 | return new ImmutableSet($this->enumClass, $set); |
|
| 43 | } |
|
| 44 | ||
| 45 | public function convertFromEnumSet(ISet $enumSet): string |
|
| 46 | { |
|