You are here

private function RequestTrait::validateMethod in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/zendframework/zend-diactoros/src/RequestTrait.php \Zend\Diactoros\RequestTrait::validateMethod()

Validate the HTTP method

Parameters

null|string $method:

Throws

InvalidArgumentException on invalid HTTP method.

2 calls to RequestTrait::validateMethod()
RequestTrait::initialize in vendor/zendframework/zend-diactoros/src/RequestTrait.php
Initialize request state.
RequestTrait::withMethod in vendor/zendframework/zend-diactoros/src/RequestTrait.php
Return an instance with the provided HTTP method.

File

vendor/zendframework/zend-diactoros/src/RequestTrait.php, line 263

Class

RequestTrait
Trait with common request behaviors.

Namespace

Zend\Diactoros

Code

private function validateMethod($method) {
  if (null === $method) {
    return;
  }
  if (!is_string($method)) {
    throw new InvalidArgumentException(sprintf('Unsupported HTTP method; must be a string, received %s', is_object($method) ? get_class($method) : gettype($method)));
  }
  if (!preg_match('/^[!#$%&\'*+.^_`\\|~0-9a-z-]+$/i', $method)) {
    throw new InvalidArgumentException(sprintf('Unsupported HTTP method "%s" provided', $method));
  }
}