2
0
Web/HTTPMethod.php

40 lines
896 B
PHP

<?php
/**
* 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;
}
}