Skip to content

Commit 5aad0a4

Browse files
committed
[WIP] Make FormConfigBuilderInterface::getType() nullable
1 parent 81a3b72 commit 5aad0a4

File tree

5 files changed

+11
-20
lines changed

5 files changed

+11
-20
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ composer.phar
88
package.tar
99
/packages.json
1010
/.phpunit
11-

src/Symfony/Component/Form/ButtonBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
2929
protected $locked = false;
3030

3131
private bool $disabled = false;
32-
private ResolvedFormTypeInterface $type;
32+
private ?ResolvedFormTypeInterface $type = null;
3333
private string $name;
3434
private array $attributes = [];
3535
private array $options;
@@ -458,7 +458,7 @@ public function getCompound(): bool
458458
/**
459459
* Returns the form type used to construct the button.
460460
*/
461-
public function getType(): ResolvedFormTypeInterface
461+
public function getType(): ?ResolvedFormTypeInterface
462462
{
463463
return $this->type;
464464
}

src/Symfony/Component/Form/FormConfigBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class FormConfigBuilder implements FormConfigBuilderInterface
4141
private bool $byReference = true;
4242
private bool $inheritData = false;
4343
private bool $compound = false;
44-
private ResolvedFormTypeInterface $type;
44+
private ?ResolvedFormTypeInterface $type = null;
4545
private array $viewTransformers = [];
4646
private array $modelTransformers = [];
4747
private ?DataMapperInterface $dataMapper = null;
@@ -239,7 +239,7 @@ public function getCompound(): bool
239239
/**
240240
* {@inheritdoc}
241241
*/
242-
public function getType(): ResolvedFormTypeInterface
242+
public function getType(): ?ResolvedFormTypeInterface
243243
{
244244
return $this->type;
245245
}

src/Symfony/Component/Form/FormConfigInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function getCompound(): bool;
6666
/**
6767
* Returns the resolved form type used to construct the form.
6868
*/
69-
public function getType(): ResolvedFormTypeInterface;
69+
public function getType(): ?ResolvedFormTypeInterface;
7070

7171
/**
7272
* Returns the view transformers of the form.

src/Symfony/Component/Form/MissingDataHandler.php

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,16 @@ public function handle(FormInterface $form, mixed $data): mixed
3131

3232
private function handleMissingData(FormInterface $form, mixed $data): mixed
3333
{
34-
try {
35-
if ($form->getConfig()->getType() instanceof ResolvedFormTypeInterface && $form->getConfig()->getType()->getInnerType() instanceof CheckboxType) {
36-
$falseValues = $form->getConfig()->getOption('false_values');
34+
if ($form->getConfig()->getType() instanceof ResolvedFormTypeInterface && $form->getConfig()->getType()->getInnerType() instanceof CheckboxType) {
35+
$falseValues = $form->getConfig()->getOption('false_values');
3736

38-
if ($data === $this->missingData) {
39-
return $falseValues[0];
40-
}
41-
42-
if (\in_array($data, $falseValues)) {
43-
return $data;
44-
}
37+
if ($data === $this->missingData) {
38+
return $falseValues[0];
4539
}
46-
} catch (\Error $error) {
47-
if ('Typed property Symfony\Component\Form\FormConfigBuilder::$type must not be accessed before initialization' === $error->getMessage()) {
40+
41+
if (\in_array($data, $falseValues)) {
4842
return $data;
4943
}
50-
51-
throw $error;
5244
}
5345

5446
if (null === $data || $this->missingData === $data) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy