Oihana PHP Enums

HttpMethod uses ConstantsTrait

Defines constants for common HTTP request methods.

Constants are organised in three sections:

  1. Standard methods — the HTTP verbs recognised by self::isValid(): the RFC 9110 §9 core methods (plus PATCH from RFC 5789) and the widely deployed PURGE extension. Each is exposed in two casings: an uppercase form matching the canonical, case-sensitive token sent on the wire, and a lowercase alias convenient for routing tables and configuration keys.

  2. RFC 5323 (WebDAV SEARCH) — the SEARCH method, an IANA-registered extension for server-side search over a collection. Registered, but not a core HTTP verb, hence intentionally excluded from self::isValid().

  3. Extras — tokens that are not HTTP verbs: a wildcard (ALL), the non-standard COUNT, and a small lowercase CRUD/command vocabulary (insert, upsert, flush, …) used by higher-level data layers. These are also excluded from self::isValid().

Example:

$request = $factory->createRequest( HttpMethod::GET , $uri ) ;

HttpMethod::isValid( 'POST' ) ;   // true
HttpMethod::isValid( 'SEARCH' ) ; // false (registry extension, not a core verb)
HttpMethod::isValid( 'flush' ) ;  // false (operation alias, not an HTTP verb)
Tags
see
https://www.iana.org/assignments/http-methods/http-methods.xhtml
author

Marc Alcaraz (ekameleon)

since
1.0.0

Table of Contents

Constants

ALL  : string = 'ALL'
`ALL` — Wildcard token matching any method, e.g. when registering a catch-all route.
all  : string = 'all'
`all` — Operation alias targeting every record of a collection.
CONNECT  : string = 'CONNECT'
`CONNECT` — Establishes a tunnel to the server, typically for TLS proxying (RFC 9110 §9.3.6).
connect  : string = 'connect'
`connect` — Lowercase form of {@see self::CONNECT}.
COUNT  : string = 'COUNT'
`COUNT` — Non-standard; returns the number of matching resources without their bodies.
count  : string = 'count'
`count` — Operation alias returning the number of matching records.
default  : string = 'default'
`default` — Fallback operation used when no specific method is provided.
DELETE  : string = 'DELETE'
`DELETE` — Removes the target resource (RFC 9110 §9.3.5).
delete  : string = 'delete'
`delete` — Lowercase form of {@see self::DELETE}.
deleteAll  : string = 'deleteAll'
`deleteAll` — Bulk operation removing every record of a collection.
exist  : string = 'exist'
`exist` — Operation alias checking whether a record exists.
flush  : string = 'flush'
`flush` — Operation alias clearing a cache or buffer.
GET  : string = 'GET'
`GET` — Requests a representation of the target resource; safe and idempotent (RFC 9110 §9.3.1).
get  : string = 'get'
`get` — Lowercase form of {@see self::GET}.
HEAD  : string = 'HEAD'
`HEAD` — Identical to `GET` but returns headers only, no body (RFC 9110 §9.3.2).
head  : string = 'head'
`head` — Lowercase form of {@see self::HEAD}.
insert  : string = 'insert'
`insert` — Operation alias creating a new record.
list  : string = 'list'
`list` — Operation alias retrieving a collection of records.
OPTIONS  : string = 'OPTIONS'
`OPTIONS` — Describes the communication options for the target resource (RFC 9110 §9.3.7).
options  : string = 'options'
`options` — Lowercase form of {@see self::OPTIONS}.
PATCH  : string = 'PATCH'
`PATCH` — Applies a partial modification to the target resource (RFC 5789).
patch  : string = 'patch'
`patch` — Lowercase form of {@see self::PATCH}.
POST  : string = 'POST'
`POST` — Submits an entity to the resource, often changing server state (RFC 9110 §9.3.3).
post  : string = 'post'
`post` — Lowercase form of {@see self::POST}.
PURGE  : string = 'PURGE'
`PURGE` — Non-standard; invalidates a cached representation (Varnish, Squid, …).
purge  : string = 'purge'
`purge` — Lowercase form of {@see self::PURGE}.
PUT  : string = 'PUT'
`PUT` — Replaces the target resource with the request payload; idempotent (RFC 9110 §9.3.4).
put  : string = 'put'
`put` — Lowercase form of {@see self::PUT}.
replace  : string = 'replace'
`replace` — Operation alias fully replacing an existing record (`PUT`-like).
SEARCH  : string = 'SEARCH'
`SEARCH` — Server-side search over a resource collection (RFC 5323, WebDAV SEARCH).
search  : string = 'search'
`search` — Lowercase form of {@see self::SEARCH}.
TRACE  : string = 'TRACE'
`TRACE` — Performs a message loop-back test along the path to the target (RFC 9110 §9.3.8).
trace  : string = 'trace'
`trace` — Lowercase form of {@see self::TRACE}.
truncate  : string = 'truncate'
`truncate` — Operation alias emptying a collection of all its records.
update  : string = 'update'
`update` — Operation alias applying a partial change to a record.
upsert  : string = 'upsert'
`upsert` — Operation alias inserting a record or updating it when it already exists.

Methods

isValid()  : bool
Checks whether a given HTTP method is a valid standard HTTP method.

Constants

ALL

`ALL` — Wildcard token matching any method, e.g. when registering a catch-all route.

public string ALL = 'ALL'

all

`all` — Operation alias targeting every record of a collection.

public string all = 'all'

CONNECT

`CONNECT` — Establishes a tunnel to the server, typically for TLS proxying (RFC 9110 §9.3.6).

public string CONNECT = 'CONNECT'

connect

`connect` — Lowercase form of {@see self::CONNECT}.

public string connect = 'connect'

COUNT

`COUNT` — Non-standard; returns the number of matching resources without their bodies.

public string COUNT = 'COUNT'

count

`count` — Operation alias returning the number of matching records.

public string count = 'count'

default

`default` — Fallback operation used when no specific method is provided.

public string default = 'default'

DELETE

`DELETE` — Removes the target resource (RFC 9110 §9.3.5).

public string DELETE = 'DELETE'

delete

`delete` — Lowercase form of {@see self::DELETE}.

public string delete = 'delete'

deleteAll

`deleteAll` — Bulk operation removing every record of a collection.

public string deleteAll = 'deleteAll'

exist

`exist` — Operation alias checking whether a record exists.

public string exist = 'exist'

flush

`flush` — Operation alias clearing a cache or buffer.

public string flush = 'flush'

GET

`GET` — Requests a representation of the target resource; safe and idempotent (RFC 9110 §9.3.1).

public string GET = 'GET'

get

`get` — Lowercase form of {@see self::GET}.

public string get = 'get'

HEAD

`HEAD` — Identical to `GET` but returns headers only, no body (RFC 9110 §9.3.2).

public string HEAD = 'HEAD'

head

`head` — Lowercase form of {@see self::HEAD}.

public string head = 'head'

insert

`insert` — Operation alias creating a new record.

public string insert = 'insert'

list

`list` — Operation alias retrieving a collection of records.

public string list = 'list'

OPTIONS

`OPTIONS` — Describes the communication options for the target resource (RFC 9110 §9.3.7).

public string OPTIONS = 'OPTIONS'

options

`options` — Lowercase form of {@see self::OPTIONS}.

public string options = 'options'

PATCH

`PATCH` — Applies a partial modification to the target resource (RFC 5789).

public string PATCH = 'PATCH'

patch

`patch` — Lowercase form of {@see self::PATCH}.

public string patch = 'patch'

POST

`POST` — Submits an entity to the resource, often changing server state (RFC 9110 §9.3.3).

public string POST = 'POST'

post

`post` — Lowercase form of {@see self::POST}.

public string post = 'post'

PURGE

`PURGE` — Non-standard; invalidates a cached representation (Varnish, Squid, …).

public string PURGE = 'PURGE'

purge

`purge` — Lowercase form of {@see self::PURGE}.

public string purge = 'purge'

PUT

`PUT` — Replaces the target resource with the request payload; idempotent (RFC 9110 §9.3.4).

public string PUT = 'PUT'

put

`put` — Lowercase form of {@see self::PUT}.

public string put = 'put'

replace

`replace` — Operation alias fully replacing an existing record (`PUT`-like).

public string replace = 'replace'

`SEARCH` — Server-side search over a resource collection (RFC 5323, WebDAV SEARCH).

public string SEARCH = 'SEARCH'

`search` — Lowercase form of {@see self::SEARCH}.

public string search = 'search'

TRACE

`TRACE` — Performs a message loop-back test along the path to the target (RFC 9110 §9.3.8).

public string TRACE = 'TRACE'

trace

`trace` — Lowercase form of {@see self::TRACE}.

public string trace = 'trace'

truncate

`truncate` — Operation alias emptying a collection of all its records.

public string truncate = 'truncate'

update

`update` — Operation alias applying a partial change to a record.

public string update = 'update'

upsert

`upsert` — Operation alias inserting a record or updating it when it already exists.

public string upsert = 'upsert'

Methods

isValid()

Checks whether a given HTTP method is a valid standard HTTP method.

public static isValid(string $method[, bool $caseSensitive = false ]) : bool

This method compares the input string against the list of recognized HTTP methods (GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS, TRACE, CONNECT, PURGE). By default, the check is case-insensitive, but you can enforce exact case matching by setting $caseSensitive to true.

Parameters
$method : string

The HTTP method to validate (e.g., 'GET', 'post').

$caseSensitive : bool = false

Optional. Whether the match should be case-sensitive. Defaults to false.

Tags
example
HttpMethod::isValid('POST');        // true
HttpMethod::isValid('post');        // true
HttpMethod::isValid('post', true);  // false
HttpMethod::isValid('flush');       // false
Return values
bool

Returns true if the method is a recognized HTTP method, false otherwise.

On this page

Search results