Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 7 additions & 29 deletions src/Enums/HTTPMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,13 @@

namespace Firehed\API\Enums;

use Firehed\Common\Enum;
use function class_alias;
use function version_compare;

/**
* Direct use of this class (via these static methods) is deprecated. Instead,
* implementations should rely on the Request traits.
*
* This will be converted to a native Enum in PHP 8.1.
*
* @method static HTTPMethod DELETE()
* @method static HTTPMethod GET()
* @method static HTTPMethod OPTIONS()
* @method static HTTPMethod PATCH()
* @method static HTTPMethod POST()
* @method static HTTPMethod PUT()
*/
class HTTPMethod extends Enum
{
use const PHP_VERSION;

// Other methods exist, but these are the only relevant ones for RESTful
// APIs
const GET = 'GET';
const PATCH = 'PATCH';
const POST = 'POST';
const PUT = 'PUT';
const DELETE = 'DELETE';
const OPTIONS = 'OPTIONS';

public function __toString()
{
return $this->getValue();
}
if (version_compare(PHP_VERSION, '8.1.0') >= 0) {
class_alias(HTTPMethodGTE81::class, HTTPMethod::class);
} else {
class_alias(HTTPMethodLTE80::class, HTTPMethod::class);
}
15 changes: 15 additions & 0 deletions src/Enums/HTTPMethodGTE81.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Firehed\API\Enums;

enum HTTPMethodGTE81: string
{
case GET = 'GET';
case PATCH = 'PATCH';
case POST = 'POST';
case PUT = 'PUT';
case DELETE = 'DELETE';
case OPTIONS = 'OPTIONS';
}
38 changes: 38 additions & 0 deletions src/Enums/HTTPMethodLTE80.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace Firehed\API\Enums;

use Firehed\Common\Enum;

/**
* Direct use of this class (via these static methods) is deprecated. Instead,
* implementations should rely on the Request traits.
*
* This will be converted to a native Enum in PHP 8.1.
*
* @method static HTTPMethod DELETE()
* @method static HTTPMethod GET()
* @method static HTTPMethod OPTIONS()
* @method static HTTPMethod PATCH()
* @method static HTTPMethod POST()
* @method static HTTPMethod PUT()
*/
class HTTPMethodLTE80 extends Enum
{

// Other methods exist, but these are the only relevant ones for RESTful
// APIs
const GET = 'GET';
const PATCH = 'PATCH';
const POST = 'POST';
const PUT = 'PUT';
const DELETE = 'DELETE';
const OPTIONS = 'OPTIONS';

public function __toString()
{
return $this->getValue();
}
}