Oihana PHP

PrepareMock uses trait:short

Prepares the `mock` flag of a controller request.

This boolean flag toggles the mock/simulation mode of an endpoint (returning fixture data instead of hitting real services). The trait delegates to PrepareBoolean::prepareBoolean() bound to the ControllerParam::MOCK parameter, so the request query string drives the value and, when present, the normalized boolean is written back into the parameter bag.

Tags
author

Marc Alcaraz (ekameleon)

since
1.0.0

Table of Contents

Properties

$mock  : bool
The mock flag to test the model.

Methods

initializeMock()  : static
Initialize the `mock` property.
prepareMock()  : bool|null
Prepare and returns the 'mock' value.

Properties

$mock

The mock flag to test the model.

public bool $mock = null

Methods

initializeMock()

Initialize the `mock` property.

public initializeMock([bool|array<string|int, mixed> $init = [] ]) : static

The flag is read directly when $init is a boolean, otherwise from the ControllerParam::MOCK key of the initialization array (defaulting to null).

Parameters
$init : bool|array<string|int, mixed> = []

Optional initialization array or the mock boolean value.

Return values
static

Returns the current instance for method chaining.

prepareMock()

Prepare and returns the 'mock' value.

protected prepareMock(ServerRequestInterface|null $request[, array<string|int, mixed> $args = [] ][, array<string|int, mixed>|null &$params = null ]) : bool|null
Parameters
$request : ServerRequestInterface|null

The incoming PSR-7 server request, or null when no request context is available.

$args : array<string|int, mixed> = []

The route/controller arguments that may carry an initial mock value.

$params : array<string|int, mixed>|null = null

A reference to the parameter bag updated in place with the prepared value.

Return values
bool|null

The resolved mock flag.

On this page

Search results