Flow PHP

StructureType implements Type

Read onlyYes
FinalYes
Tags
template-covariant

of array<array-key, mixed>

implements

Interfaces

Type

Methods

__construct()  : mixed
allowsExtra()  : bool
assert()  : T
Checks that the value is of the type of this object, throwing when it is not.
cast()  : T
Takes a value and when necessary casts it to the type of this object.
element()  : null|StructureElement<string|int, T>>
elements()  : array<int, StructureElement<string|int, T>>>
fromArray()  : StructureType<string|int, array<string|int, mixed>>
fromElements()  : E>>
isValid()  : bool
Checks if the value is of the type of this object, returning a boolean instead of throwing.
normalize()  : array{type: "structure_v2", fields: list, optional: bool}>, allow_extra: bool}
toString()  : string
Returns a string representation of the type.

Methods

allowsExtra()

public allowsExtra() : bool
Return values
bool

assert()

Checks that the value is of the type of this object, throwing when it is not.

public assert(mixed $value) : T
Parameters
$value : mixed
Return values
T

cast()

Takes a value and when necessary casts it to the type of this object.

public cast(mixed $value) : T
Parameters
$value : mixed
Return values
T

fromArray()

public static fromArray(array<string, mixed> $data) : StructureType<string|int, array<string|int, mixed>>
Parameters
$data : array<string, mixed>
Return values
StructureType<string|int, array<string|int, mixed>>

fromElements()

public static fromElements(array<string|int, StructureElement<string|int, E>|Type<string|int, E>> $elements[, bool $allowExtra = false ]) : E>>
Parameters
$elements : array<string|int, StructureElement<string|int, E>|Type<string|int, E>>

insertion order is field order; a StructureElement value carries its own optional flag

$allowExtra : bool = false
Tags
template
Return values
E>>

isValid()

Checks if the value is of the type of this object, returning a boolean instead of throwing.

public isValid(mixed $value) : bool

When this method returns true, static analysis tools narrow the value's type to T at the call site (via @assert-if-true). Use this when you want to branch on the result; use assert() when you want the call to fail loudly on a mismatch.

Parameters
$value : mixed
Return values
bool

normalize()

public normalize() : array{type: "structure_v2", fields: list, optional: bool}>, allow_extra: bool}
Return values
array{type: "structure_v2", fields: list, optional: bool}>, allow_extra: bool}

toString()

Returns a string representation of the type.

public toString() : string
  • string - for type_string()
  • int - for type_int()
  • ?float - for type_optional(type_float())
Return values
string
On this page

Search results