Skip to content

Metadata

Miscellaneous

Other options of classes, properties and enums.

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.

Normalizes objects of the class into an associative array (true) or into stdClass (false). Overrides the configuration option.

use TypeLang\Mapper\Mapping\NormalizeAsArray;
#[NormalizeAsArray(false)]
final class User
{
public string $name = 'Ada';
}
$mapper->normalize(new User()); // (object) ['name' => 'Ada']

The value of a missing field. A property without a default value is required.

$mapper->denormalize(['name' => 'Ada'], User::class);
// User { name: 'Ada', role: 'user' }

Other values accepted for a case of a backed enum, such as old values. Normalization always gives the value of the case.

use TypeLang\Mapper\Mapping\MapAlias;
enum Status: string
{
#[MapAlias(['enabled', 'on'])]
case Active = 'active';
case Blocked = 'blocked';
}
$mapper->denormalize('on', Status::class); // Status::Active
$mapper->normalize(Status::Active); // 'active'