42 lines
765 B
PHP
42 lines
765 B
PHP
<?php
|
|
|
|
namespace Web;
|
|
|
|
/**
|
|
* HTTPMethod represents an HTTP method
|
|
*/
|
|
enum HTTPMethod: string {
|
|
case GET = 'GET';
|
|
case POST = 'POST';
|
|
case PUT = 'PUT';
|
|
case DELETE = 'DELETE';
|
|
case PATCH = 'PATCH';
|
|
case OPTIONS = 'OPTIONS';
|
|
case HEAD = 'HEAD';
|
|
|
|
/**
|
|
* fromString converts a string to an HTTPMethod
|
|
*/
|
|
public static function fromString(string $method): self
|
|
{
|
|
return match(strtoupper($method)) {
|
|
'GET' => self::GET,
|
|
'POST' => self::POST,
|
|
'PUT' => self::PUT,
|
|
'DELETE' => self::DELETE,
|
|
'PATCH' => self::PATCH,
|
|
'OPTIONS' => self::OPTIONS,
|
|
'HEAD' => self::HEAD,
|
|
default => self::GET
|
|
};
|
|
}
|
|
|
|
/**
|
|
* toString returns the string representation of the method
|
|
*/
|
|
public function toString(): string
|
|
{
|
|
return $this->value;
|
|
}
|
|
}
|