Skip to content

Commit 304dcfb

Browse files
committed
Implement JsonSerializable interface in Enumeration class
1 parent 51a6862 commit 304dcfb

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
],
1414
"require": {
1515
"php": "^7.4|^8.0",
16+
"ext-json": "*",
1617
"ext-mbstring": "*"
1718
},
1819
"require-dev": {

src/Enumeration.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
namespace DeSmart\Enum;
66

7+
use JsonSerializable;
78
use function DeSmart\Enum\Helpers\toConstName;
89

9-
abstract class Enumeration
10+
abstract class Enumeration implements JsonSerializable
1011
{
1112
/**
1213
* @var int|string
@@ -77,6 +78,14 @@ public function __toString(): string
7778
return (string) $this->getValue();
7879
}
7980

81+
/**
82+
* @return int|string
83+
*/
84+
public function jsonSerialize()
85+
{
86+
return $this->value;
87+
}
88+
8089
public function equals(Enumeration $other): bool
8190
{
8291
if (! $other instanceof static) {

0 commit comments

Comments
 (0)