FieldCoercion
The single source of scalar coercion shared by SchemaFormParser (enum members, defaults) and FormBinder (input). Centralizing it here removes divergence between the two seams. The rules are frozen: integer requires /^-?\d+$/ then a verbatim (int) cast (overflow clamps silently); number uses is_numeric then (float); the empty check is always strict `=== ''` so "0" is not empty.
FieldCoercion::toInt()
public static function toInt(string $str): ?intA normalized (trimmed, non-empty) string to an int, or null if it is not an integer literal.
Parameters
| Name | Type | Description |
|---|---|---|
| $str | string |
FieldCoercion::toFloat()
public static function toFloat(string $str): ?floatA normalized (trimmed, non-empty) string to a float, or null if it is not numeric.
Parameters
| Name | Type | Description |
|---|---|---|
| $str | string |
FieldCoercion::toBool()
public static function toBool(string $str): ?boolA normalized (lowercased, trimmed) string to a bool via the frozen token sets, or null.
Parameters
| Name | Type | Description |
|---|---|---|
| $str | string |
FieldCoercion::coerceEnumMember()
public static function coerceEnumMember(?mixed $value, Milpa\Live\Schema\FieldType $type): string|int|float|nullCoerces one enum member (or any non-boolean schema value) to the field's base type. Non-scalar or boolean members are rejected (null) BEFORE any string cast — no E_WARNING is ever emitted.
Parameters
| Name | Type | Description |
|---|---|---|
| $value | ?mixed | |
| $type | Milpa\Live\Schema\FieldType |
FieldCoercion::coerceDefault()
public static function coerceDefault(?mixed $value, Milpa\Live\Schema\FieldType $type): string|int|float|bool|nullCoerces a field default to the base type. Boolean accepts a native bool or a token string; the other types reuse coerceEnumMember. null means "not coercible to this type".
Parameters
| Name | Type | Description |
|---|---|---|
| $value | ?mixed | |
| $type | Milpa\Live\Schema\FieldType |