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.
When null
Section titled “When null”use TypeLang\Mapper\Mapping\SkipWhenNull;
final class User{ #[SkipWhenNull] public ?string $phone = null;}<?php
return [ App\User::class => [ 'properties' => [ 'phone' => [ 'skip' => 'null', ], ], ],];{ "App\\User": { "properties": { "phone": { "skip": "null" } } }}App\User: properties: phone: skip: 'null'App\User: properties: phone: skip: 'null'$mapper->normalize(new User()); // []When empty
Section titled “When empty”Skips null, false, 0, 0.0, '', '0' and [].
use TypeLang\Mapper\Mapping\SkipWhenEmpty;
final class User{ #[SkipWhenEmpty] public array $tags = [];}<?php
return [ App\User::class => [ 'properties' => [ 'tags' => [ 'skip' => 'empty', ], ], ],];{ "App\\User": { "properties": { "tags": { "skip": "empty" } } }}App\User: properties: tags: skip: emptyApp\User: properties: tags: skip: empty$mapper->normalize(new User()); // []Expression
Section titled “Expression”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';}<?php
return [ App\User::class => [ 'properties' => [ 'email' => [ 'skip' => 'this.isGuest', ], ], ],];{ "App\\User": { "properties": { "email": { "skip": "this.isGuest" } } }}App\User: properties: email: skip: this.isGuestApp\User: properties: email: skip: this.isGuest$mapper->normalize(new User()); // ['isGuest' => true]