Ejemplo n.º 1
0
 /**
  * Return an instance with the specified status code and, optionally, reason phrase.
  *
  * If no reason phrase is specified, implementations MAY choose to default
  * to the RFC 7231 or IANA recommended reason phrase for the response's
  * status code.
  *
  * This method MUST be implemented in such a way as to retain the
  * immutability of the message, and MUST return an instance that has the
  * updated status and reason phrase.
  *
  * @link http://tools.ietf.org/html/rfc7231#section-6
  * @link http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
  *
  * @param int    $code         The 3-digit integer result code to set.
  * @param string $reasonPhrase The reason phrase to use with the
  *                             provided status code; if none is provided, implementations MAY
  *                             use the defaults as suggested in the HTTP specification.
  *
  * @return static
  * @throws \InvalidArgumentException For invalid status code arguments.
  */
 public function withStatus($code, $reasonPhrase = '')
 {
     if (!ResponseHelper::validateStatus($code)) {
         throw new \InvalidArgumentException('Invalid status code: ' . $code);
     }
     $new = clone $this;
     $new->statusCode = (int) $code;
     $new->reasonPhrase = $reasonPhrase;
     return $new;
 }
 /**
  * Method to test validateStatus().
  *
  * @return void
  *
  * @covers \Windwalker\Http\Helper\ResponseHelper::validateStatus
  */
 public function testValidateStatus()
 {
     $this->assertTrue(ResponseHelper::validateStatus(200));
     $this->assertFalse(ResponseHelper::validateStatus(700));
 }
Ejemplo n.º 3
0
 /**
  * Return an instance with the specified status code and, optionally, reason phrase.
  *
  * If no reason phrase is specified, implementations MAY choose to default
  * to the RFC 7231 or IANA recommended reason phrase for the response's
  * status code.
  *
  * This method MUST be implemented in such a way as to retain the
  * immutability of the message, and MUST return an instance that has the
  * updated status and reason phrase.
  *
  * @link http://tools.ietf.org/html/rfc7231#section-6
  * @link http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
  *
  * @param int    $code         The 3-digit integer result code to set.
  * @param string $reasonPhrase The reason phrase to use with the
  *                             provided status code; if none is provided, implementations MAY
  *                             use the defaults as suggested in the HTTP specification.
  *
  * @return static
  * @throws \InvalidArgumentException For invalid status code arguments.
  */
 public function withStatus($code, $reasonPhrase = '')
 {
     $code = ResponseHelper::validateStatus($code);
     $new = clone $this;
     $new->statusCode = (int) $code;
     $new->reasonPhrase = $reasonPhrase;
     return $new;
 }