name = $this->sanitizeName($name); $this->value = $value; } public function getId(): ?int { return $this->id; } /** * @param int $id * @return UserPreference */ public function setId(int $id): UserPreference { $this->id = $id; return $this; } public function getUser(): ?User { return $this->user; } public function setUser(User $user): UserPreference { $this->user = $user; return $this; } public function getName(): ?string { return $this->sanitizeName($this->name); } public function matches(string $name): bool { return $this->sanitizeName($name) === $this->getName(); } public function sanitizeName(?string $name): string { return str_replace(['.', '-'], '_', $name); } public function getValue(): bool|int|float|string|null { return match ($this->type) { YesNoType::class, CheckboxType::class => (bool) $this->value, IntegerType::class => (int) $this->value, NumberType::class => (float) $this->value, default => $this->value, }; } /** * Given $value will not be serialized before its stored, so it should be one of the types: * integer, float, string, boolean or null * * @param mixed $value * @return UserPreference */ public function setValue($value): UserPreference { $this->value = $value; return $this; } /** * Sets the form type to edit that setting. * * @param string $type * @return UserPreference */ public function setType(string $type): UserPreference { $this->type = $type; return $this; } public function getType(): ?string { return $this->type; } public function isEnabled(): bool { return $this->enabled; } public function setEnabled(bool $enabled): UserPreference { $this->enabled = $enabled; return $this; } /** * Set the constraints which are used for validation of the value. * * @param Constraint[] $constraints * @return $this */ public function setConstraints(array $constraints) { $this->constraints = $constraints; return $this; } /** * Adds a constraint which is used for validation of the value. * * @param Constraint $constraint * @return $this */ public function addConstraint(Constraint $constraint) { $this->constraints[] = $constraint; return $this; } /** * @return Constraint[] */ public function getConstraints(): array { return $this->constraints; } /** * Set an array of options for the FormType. * * @param array $options * @return UserPreference */ public function setOptions(array $options): UserPreference { $this->options = $options; return $this; } /** * Returns an array with options for the FormType. * * @return array */ public function getOptions(): array { return $this->options; } public function getLabel(): ?string { if (isset($this->options['label'])) { return $this->options['label']; } return $this->name; } public function getOrder(): int { return $this->order; } public function setOrder(int $order): UserPreference { $this->order = $order; return $this; } public function setSection(string $section): UserPreference { $this->section = $section; return $this; } public function getSection(): string { return $this->section; } }