Constructor

Learn how to initialize a fetch response directly.

The constructor initializes the fetch response with the given content and metadata.

You normally obtain one when you fetch content instead, but you can construct it directly to provide fixed content in tests.

Signature

The constructor has the following signature:

public function __construct(mixed $content, ?SlotMetadata $metadata = null)

Example

Here is a basic example of how to create a fetch response:

<?phpuse Croct\Plug\FetchResponse;
$response = new FetchResponse(['title' => 'Welcome to Croct!']);

Parameters

The following list describes the supported parameters:

content
mixed

The resolved content of the slot.

metadata(optional)

The metadata of the resolved content. The default is null, which provides no metadata.

Default:null