Skip to content

Metadata

Skipping properties

Leaves a property out of the normalized data under a condition. Several conditions can be combined: the property is skipped when any of them matches.

Every option is shown in each metadata source: choose the tab of the source you use. When a source cannot express an option, its tab says what is used instead.

use TypeLang\Mapper\Mapping\SkipWhenNull;
final class User
{
#[SkipWhenNull]
public ?string $phone = null;
}
$mapper->normalize(new User()); // []

Skips null, false, 0, 0.0, '', '0' and [].

use TypeLang\Mapper\Mapping\SkipWhenEmpty;
final class User
{
#[SkipWhenEmpty]
public array $tags = [];
}
$mapper->normalize(new User()); // []

An expression of the Symfony Expression Language, this is the object. Requires symfony/expression-language.

use TypeLang\Mapper\Mapping\SkipWhen;
final class User
{
public bool $isGuest = true;
#[SkipWhen('this.isGuest')]
public string $email = 'guest@example.com';
}
$mapper->normalize(new User()); // ['isGuest' => true]