Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/mantle/http-client/class-response.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use LogicException;
use Mantle\Support\Collection;
use Mantle\Support\Traits\Macroable;
use Mantle\Support\Traits\Response_Assertions;
use SimpleXMLElement;
use WP_Error;
use WP_Http_Cookie;
Expand Down Expand Up @@ -48,6 +49,7 @@
*/
class Response implements ArrayAccess {
use Macroable;
use Response_Assertions;

/**
* The decoded JSON response.
Expand Down Expand Up @@ -425,4 +427,42 @@ public function offsetSet( mixed $offset, mixed $value ): void {
public function offsetUnset( mixed $offset ): void {
throw new LogicException( 'Response values are read-only.' );
}

/**
* Implementation for Response_Assertions trait.
* Get the response status code.
*/
protected function getResponseStatusCode(): int {
return $this->status();
}

/**
* Implementation for Response_Assertions trait.
* Get a response header.
*
* @param string $header Header name.
* @param mixed $default Default value if header not found.
* @return mixed
*/
protected function getResponseHeader( string $header, mixed $default = null ): mixed {
return $this->header( $header ) ?? $default;
}

/**
* Implementation for Response_Assertions trait.
* Get the response content/body.
*/
protected function getResponseContent(): ?string {
return $this->body();
}

/**
* Implementation for Response_Assertions trait.
* Get all response headers.
*
* @return array<string, mixed>
*/
protected function getResponseHeaders(): array {
return $this->headers();
}
}
Loading