vendor/dachcom-digital/formbuilder/src/FormBuilderBundle/Form/Data/FormData.php line 8

Open in your IDE?
  1. <?php
  2. namespace FormBuilderBundle\Form\Data;
  3. use FormBuilderBundle\Model\FormDefinitionInterface;
  4. use FormBuilderBundle\Stream\File;
  5. class FormData implements FormDataInterface
  6. {
  7.     protected FormDefinitionInterface $formDefinition;
  8.     protected array $data = [];
  9.     protected array $attachments = [];
  10.     public function __construct(FormDefinitionInterface $formDefinition, array $data = [])
  11.     {
  12.         $this->formDefinition = $formDefinition;
  13.         $this->data = $data;
  14.     }
  15.     public function getFormDefinition(): FormDefinitionInterface
  16.     {
  17.         return $this->formDefinition;
  18.     }
  19.     public function getData(): array
  20.     {
  21.         return $this->data;
  22.     }
  23.     public function hasAttachments(): bool
  24.     {
  25.         return count($this->attachments) > 0;
  26.     }
  27.     public function getAttachments(): array
  28.     {
  29.         return array_values($this->attachments);
  30.     }
  31.     public function addAttachment(File $attachmentFile): void
  32.     {
  33.         if (array_key_exists($attachmentFile->getId(), $this->attachments)) {
  34.             return;
  35.         }
  36.         $this->attachments[$attachmentFile->getId()] = $attachmentFile;
  37.     }
  38.     public function getFieldValue(string $name): mixed
  39.     {
  40.         $array = $this->getData();
  41.         if (isset($array[$name])) {
  42.             return $array[$name];
  43.         }
  44.         return null;
  45.     }
  46.     public function setFieldValue(string $name, $value): void
  47.     {
  48.         $this->data[$name] = $value;
  49.     }
  50.     public function __set(string $name, mixed $value)
  51.     {
  52.         $this->data[$name] = $value;
  53.     }
  54.     public function __isset(string $name): bool
  55.     {
  56.         if (!is_string($name)) {
  57.             return false;
  58.         }
  59.         $data = $this->getData();
  60.         return isset($data[$name]);
  61.     }
  62.     public function __get(string $name): mixed
  63.     {
  64.         return $this->getFieldValue($name);
  65.     }
  66. }