Lukasoppermann\Httpstatus\Httpstatus::getStatusCode PHP 메소드

getStatusCode() 공개 메소드

Get the code for a given status text.
public getStatusCode ( string $statusText ) : string
$statusText string http status text
리턴 string Returns code for the given status text
    public function getStatusCode($statusText)
    {
        $statusText = $this->filterReasonPhrase($statusText);
        $statusCode = $this->fetchStatusCode($statusText);
        if ($statusCode !== false) {
            return $statusCode;
        }
        throw new OutOfBoundsException(sprintf('No Http status code is associated to `%s`', $statusText));
    }

Usage Example

예제 #1
0
 /**
  * Get the response with the status code from the payload.
  *
  * @param ResponseInterface $response
  * @param PayloadInterface $payload
  *
  * @return ResponseInterface
  */
 private function status(ResponseInterface $response, PayloadInterface $payload)
 {
     $status = $payload->getStatus();
     $code = $this->http_status->getStatusCode($status);
     return $response->withStatus($code);
 }