*/ public const DEFAULT_SUPPORTED_DATETIME_FORMATS = [ 'Y-m-d\\TH:i:sP', // RFC 3339 'Y-m-d\\TH:i:s.uP', // RFC 3339 with microseconds 'U', // Unix Timestamp 'U.u', // Unix Timestamp with microseconds ]; /** @var array */ public array $inferredMapping = []; /** @var array */ public array $nativeConstructors = []; /** @var list */ public array $customConstructors = []; /** @pure */ public Cache $cache; /** @var non-empty-list */ public array $supportedDateFormats = self::DEFAULT_SUPPORTED_DATETIME_FORMATS; public bool $allowScalarValueCasting = false; public bool $allowNonSequentialList = false; public bool $allowUndefinedValues = false; public bool $allowSuperfluousKeys = false; public bool $allowPermissiveTypes = false; /** @var array> */ public array $mapperConverters = []; /** @var array */ public array $mapperConverterAttributes = []; /** @var callable(Throwable): ErrorMessage */ public mixed $exceptionFilter; /** @var array> */ public array $normalizerTransformers = []; /** @var array */ public array $normalizerTransformerAttributes = []; private string $hash; public function __construct() { $this->inferredMapping[DateTimeInterface::class] = static fn () => DateTimeImmutable::class; $this->exceptionFilter = fn (Throwable $exception) => throw $exception; } /** * @return non-empty-list */ public function allowedAttributes(): array { return [ Constructor::class, DynamicConstructor::class, ...array_keys($this->mapperConverterAttributes), ...array_keys($this->normalizerTransformerAttributes), ]; } /** * @return list */ public function convertersSortedByPriority(): array { krsort($this->mapperConverters); $callables = []; foreach ($this->mapperConverters as $list) { $callables = [...$callables, ...$list]; } return $callables; } /** * @return list */ public function transformersSortedByPriority(): array { krsort($this->normalizerTransformers); $callables = []; foreach ($this->normalizerTransformers as $list) { $callables = [...$callables, ...$list]; } return $callables; } /** * Returns a unique hash, based on all the settings values that were set in * this instance. */ public function hash(): string { return $this->hash ??= hash('xxh128', serialize([ $this->nativeConstructors, $this->supportedDateFormats, $this->allowScalarValueCasting, $this->allowNonSequentialList, $this->allowUndefinedValues, $this->allowSuperfluousKeys, $this->allowPermissiveTypes, $this->mapperConverterAttributes, $this->normalizerTransformerAttributes, implode('', array_map(function (callable $callable) { $reflection = new ReflectionFunction(Closure::fromCallable($callable)); return ($reflection->getClosureCalledClass()->name ?? $reflection->getFileName()) . $reflection->getStartLine() . $reflection->getEndLine(); }, $this->callables())), ])); } /** * @return non-empty-list */ public function callables(): array { return array_values([ $this->exceptionFilter, ...$this->inferredMapping, ...$this->customConstructors, ...array_merge(...$this->mapperConverters), ...array_merge(...$this->normalizerTransformers), ]); } }