DA
Size: a a a
AV
V
️️
DA
️️
СП
public static function toNullOrString($value, ?array $nullValues = ['']): ?stringВариант 2
{
$caster = (new CompositeCaster())->define(new NullCaster(['nullValues' => $nullValues]), new StringCaster());
return $caster->apply($value);
}
public static function toNullOrString($value, ?array $nullValues = ['']): ?stringPHP7.2+
{
static $casters;
$hash = md5(serialize($nullValues));
if (!isset($casters[$hash])) {
$casters[$hash] = (new CompositeCaster())->define(new NullCaster(['nullValues' => $nullValues]), new StringCaster());
}
return $casters[$hash]->apply($value);
}
CompositeCaster
, NullCaster
и StringCaster
предельно простые.P
DA
DA
️️
u
u
u