-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce more enum classes and introduce a base enum class
- Loading branch information
Showing
14 changed files
with
119 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace Chiphpotle\Rest\Enum; | ||
|
||
|
||
final class AlgebraicOperation extends BaseEnum | ||
{ | ||
public const UNSPECIFIED = 'OPERATION_UNSPECIFIED'; | ||
public const UNION = 'OPERATION_UNION'; | ||
public const INTERSECTION = 'OPERATION_INTERSECTION'; | ||
public const EXCLUSION = 'OPERATION_EXCLUSION'; | ||
public static function allowableValues(): array | ||
{ | ||
return [self::UNION, self::INTERSECTION, self::EXCLUSION]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Chiphpotle\Rest\Enum; | ||
|
||
use Chiphpotle\Rest\Runtime\Normalizer\ValidationException; | ||
|
||
abstract class BaseEnum | ||
{ | ||
/** | ||
* @return string[] | ||
*/ | ||
abstract public static function allowableValues(): array; | ||
|
||
public static function validate(string $value): void | ||
{ | ||
if (!in_array($value, static::allowableValues())) { | ||
$class = get_called_class(); | ||
$shortClass = substr($class, strrpos($class, '\\') + 1); | ||
throw new ValidationException("Invalid enum value for $shortClass"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace Chiphpotle\Rest\Enum; | ||
|
||
|
||
final class LookupPermissionship extends BaseEnum | ||
{ | ||
public const UNSPECIFIED = 'LOOKUP_PERMISSIONSHIP_UNSPECIFIED'; | ||
public const HAS_PERMISSION = 'LOOKUP_PERMISSIONSHIP_HAS_PERMISSION'; | ||
public const CONDITIONAL_PERMISSION = 'LOOKUP_PERMISSIONSHIP_CONDITIONAL_PERMISSION'; | ||
|
||
public static function allowableValues(): array | ||
{ | ||
return [self::HAS_PERMISSION, self::CONDITIONAL_PERMISSION]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace Chiphpotle\Rest\Enum; | ||
|
||
final class PreconditionOperation extends BaseEnum | ||
{ | ||
public const UNSPECIFIED = 'OPERATION_UNSPECIFIED'; | ||
public const MUST_MATCH = 'OPERATION_MUST_MATCH'; | ||
public const MUST_NOT_MATCH = 'OPERATION_MUST_NOT_MATCH'; | ||
|
||
public static function allowableValues(): array | ||
{ | ||
return [self::MUST_MATCH, self::MUST_NOT_MATCH]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters