Skip to content

Commit a0c1231

Browse files
committed
Further real dev updates
make the generateEnumArray method public
1 parent a4ef6c6 commit a0c1231

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ Copy the `json-schema.php` file from the `vendor/carsdotcom/laravel-json-schema/
4545

4646
#### Generate Enum Schemas
4747

48-
This is an optional step, but can be super helpful.
48+
_This is an optional step, but can be super helpful._
49+
50+
Note: Enums must be created either as a built-in PHP `enum` object or a `MyCLabs\Enum\Enum` class.
4951

5052
1. Add `use Carsdotcom\JsonSchemaValidation\Traits\GeneratesSchemaTrait;` to the declarations in the Enum.
5153
2. Add a `SCHEMA` constant to the enum. It's value will be the relative path to your schema file, such as: `const SCHEMA = '/Acme/Enums/item_type.json';`

app/Traits/GeneratesSchemaTrait.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,7 @@ public static function generateSchema(): void
5858

5959
}
6060

61-
protected static function isPhpBuiltInEnum(): bool
62-
{
63-
return is_a(static::class, UnitEnum::class, true);
64-
}
65-
66-
protected static function getMyCLabsClass(): string
67-
{
68-
return 'MyCLabs\Enum\Enum';
69-
}
70-
71-
protected static function isMyCLabsEnum(): bool
72-
{
73-
return is_a(static::class, static::getMyCLabsClass(), true);
74-
}
75-
76-
protected static function generateEnumArray(): array
61+
public static function generateEnumArray(): array
7762
{
7863
if (static::isMyCLabsEnum()) {
7964
return static::generateMyCLabsEnumArray();
@@ -94,4 +79,19 @@ protected static function generateMyCLabsEnumArray(): array
9479

9580
return array_values(array_unique($array));
9681
}
82+
83+
protected static function isPhpBuiltInEnum(): bool
84+
{
85+
return is_a(static::class, UnitEnum::class, true);
86+
}
87+
88+
protected static function getMyCLabsClass(): string
89+
{
90+
return 'MyCLabs\Enum\Enum';
91+
}
92+
93+
protected static function isMyCLabsEnum(): bool
94+
{
95+
return is_a(static::class, static::getMyCLabsClass(), true);
96+
}
9797
}

0 commit comments

Comments
 (0)