Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 967fa36

Browse filesBrowse files
committed
bug #30879 [Form] Php doc fixes and cs + optimizations (Jules Pietri)
This PR was merged into the 3.4 branch. Discussion ---------- [Form] Php doc fixes and cs + optimizations | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | no <!-- don't forget to update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | ~ | License | MIT | Doc PR | ~ <!-- Write a short README entry for your feature/bugfix here (replace this comment block.) This will help people understand your PR and can be used as a start of the Doc PR. Additionally: - Bug fixes must be submitted against the lowest branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against the master branch. --> Some micro optimizations may target master with some profiling but I would like some reviews first. Thanks! Commits ------- 56429a6 [Form] various minor fixes
2 parents d77ea48 + 56429a6 commit 967fa36
Copy full SHA for 967fa36

26 files changed

+370
-318
lines changed

‎src/Symfony/Component/Form/AbstractExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/AbstractExtension.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ abstract class AbstractExtension implements FormExtensionInterface
3636
/**
3737
* The type guesser provided by this extension.
3838
*
39-
* @var FormTypeGuesserInterface
39+
* @var FormTypeGuesserInterface|null
4040
*/
4141
private $typeGuesser;
4242

@@ -136,7 +136,7 @@ protected function loadTypeExtensions()
136136
/**
137137
* Registers the type guesser.
138138
*
139-
* @return FormTypeGuesserInterface|null A type guesser
139+
* @return FormTypeGuesserInterface|null
140140
*/
141141
protected function loadTypeGuesser()
142142
{

‎src/Symfony/Component/Form/AbstractRendererEngine.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/AbstractRendererEngine.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ abstract protected function loadResourceForBlockName($cacheKey, FormView $view,
133133
* resource
134134
* @param FormView $view The form view for finding the applying
135135
* themes
136-
* @param array $blockNameHierarchy The block hierarchy, with the most
136+
* @param string[] $blockNameHierarchy The block hierarchy, with the most
137137
* specific block name at the end
138138
* @param int $hierarchyLevel The level in the block hierarchy that
139139
* should be loaded

‎src/Symfony/Component/Form/Button.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Button.php
+17-8Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
class Button implements \IteratorAggregate, FormInterface
2323
{
2424
/**
25-
* @var FormInterface|null
25+
* @var FormInterface
2626
*/
2727
private $parent;
2828

@@ -111,6 +111,8 @@ public function setParent(FormInterface $parent = null)
111111
}
112112

113113
$this->parent = $parent;
114+
115+
return $this;
114116
}
115117

116118
/**
@@ -199,32 +201,37 @@ public function getErrors($deep = false, $flatten = true)
199201
* This method should not be invoked.
200202
*
201203
* @param mixed $modelData
204+
*
205+
* @return $this
202206
*/
203207
public function setData($modelData)
204208
{
205-
// called during initialization of the form tree
206-
// noop
209+
// no-op, called during initialization of the form tree
210+
return $this;
207211
}
208212

209213
/**
210214
* Unsupported method.
211215
*/
212216
public function getData()
213217
{
218+
return null;
214219
}
215220

216221
/**
217222
* Unsupported method.
218223
*/
219224
public function getNormData()
220225
{
226+
return null;
221227
}
222228

223229
/**
224230
* Unsupported method.
225231
*/
226232
public function getViewData()
227233
{
234+
return null;
228235
}
229236

230237
/**
@@ -240,7 +247,7 @@ public function getExtraData()
240247
/**
241248
* Returns the button's configuration.
242249
*
243-
* @return FormConfigInterface The configuration
250+
* @return FormConfigInterface The configuration instance
244251
*/
245252
public function getConfig()
246253
{
@@ -272,6 +279,7 @@ public function getName()
272279
*/
273280
public function getPropertyPath()
274281
{
282+
return null;
275283
}
276284

277285
/**
@@ -309,11 +317,11 @@ public function isRequired()
309317
*/
310318
public function isDisabled()
311319
{
312-
if (null === $this->parent || !$this->parent->isDisabled()) {
313-
return $this->config->getDisabled();
320+
if ($this->parent && $this->parent->isDisabled()) {
321+
return true;
314322
}
315323

316-
return true;
324+
return $this->config->getDisabled();
317325
}
318326

319327
/**
@@ -341,6 +349,7 @@ public function isSynchronized()
341349
*/
342350
public function getTransformationFailure()
343351
{
352+
return null;
344353
}
345354

346355
/**
@@ -368,7 +377,7 @@ public function handleRequest($request = null)
368377
/**
369378
* Submits data to the button.
370379
*
371-
* @param string|null $submittedData The data
380+
* @param string|null $submittedData Not used
372381
* @param bool $clearMissing Not used
373382
*
374383
* @return $this

‎src/Symfony/Component/Form/ButtonBuilder.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/ButtonBuilder.php
+10-5Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
*/
2323
class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
2424
{
25-
/**
26-
* @var bool
27-
*/
2825
protected $locked = false;
2926

3027
/**
@@ -53,8 +50,6 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
5350
private $options;
5451

5552
/**
56-
* Creates a new button builder.
57-
*
5853
* @param string $name The name of the button
5954
* @param array $options The button's options
6055
*
@@ -524,6 +519,7 @@ public function getFormConfig()
524519
*/
525520
public function getEventDispatcher()
526521
{
522+
return null;
527523
}
528524

529525
/**
@@ -539,6 +535,7 @@ public function getName()
539535
*/
540536
public function getPropertyPath()
541537
{
538+
return null;
542539
}
543540

544541
/**
@@ -606,6 +603,7 @@ public function getModelTransformers()
606603
*/
607604
public function getDataMapper()
608605
{
606+
return null;
609607
}
610608

611609
/**
@@ -643,6 +641,7 @@ public function getErrorBubbling()
643641
*/
644642
public function getEmptyData()
645643
{
644+
return null;
646645
}
647646

648647
/**
@@ -685,13 +684,15 @@ public function getAttribute($name, $default = null)
685684
*/
686685
public function getData()
687686
{
687+
return null;
688688
}
689689

690690
/**
691691
* Unsupported method.
692692
*/
693693
public function getDataClass()
694694
{
695+
return null;
695696
}
696697

697698
/**
@@ -709,27 +710,31 @@ public function getDataLocked()
709710
*/
710711
public function getFormFactory()
711712
{
713+
throw new BadMethodCallException('Buttons do not support adding children.');
712714
}
713715

714716
/**
715717
* Unsupported method.
716718
*/
717719
public function getAction()
718720
{
721+
return null;
719722
}
720723

721724
/**
722725
* Unsupported method.
723726
*/
724727
public function getMethod()
725728
{
729+
return null;
726730
}
727731

728732
/**
729733
* Unsupported method.
730734
*/
731735
public function getRequestHandler()
732736
{
737+
return null;
733738
}
734739

735740
/**

‎src/Symfony/Component/Form/CallbackTransformer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/CallbackTransformer.php
+2-20Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111

1212
namespace Symfony\Component\Form;
1313

14-
use Symfony\Component\Form\Exception\TransformationFailedException;
15-
use Symfony\Component\Form\Exception\UnexpectedTypeException;
16-
1714
class CallbackTransformer implements DataTransformerInterface
1815
{
1916
private $transform;
@@ -30,30 +27,15 @@ public function __construct(callable $transform, callable $reverseTransform)
3027
}
3128

3229
/**
33-
* Transforms a value from the original representation to a transformed representation.
34-
*
35-
* @param mixed $data The value in the original representation
36-
*
37-
* @return mixed The value in the transformed representation
38-
*
39-
* @throws UnexpectedTypeException when the argument is not of the expected type
40-
* @throws TransformationFailedException when the transformation fails
30+
* {@inheritdoc}
4131
*/
4232
public function transform($data)
4333
{
4434
return \call_user_func($this->transform, $data);
4535
}
4636

4737
/**
48-
* Transforms a value from the transformed representation to its original
49-
* representation.
50-
*
51-
* @param mixed $data The value in the transformed representation
52-
*
53-
* @return mixed The value in the original representation
54-
*
55-
* @throws UnexpectedTypeException when the argument is not of the expected type
56-
* @throws TransformationFailedException when the transformation fails
38+
* {@inheritdoc}
5739
*/
5840
public function reverseTransform($data)
5941
{

‎src/Symfony/Component/Form/DataMapperInterface.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/DataMapperInterface.php
+32-8Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,46 @@
1717
interface DataMapperInterface
1818
{
1919
/**
20-
* Maps properties of some data to a list of forms.
20+
* Maps the view data of a compound form to its children.
2121
*
22-
* @param mixed $data Structured data
23-
* @param FormInterface[]|\Traversable $forms A list of {@link FormInterface} instances
22+
* The method is responsible for calling {@link FormInterface::setData()}
23+
* on the children of compound forms, defining their underlying model data.
24+
*
25+
* @param mixed $viewData View data of the compound form being initialized
26+
* @param FormInterface[]|\Traversable $forms A list of {@link FormInterface} instances
2427
*
2528
* @throws Exception\UnexpectedTypeException if the type of the data parameter is not supported
2629
*/
27-
public function mapDataToForms($data, $forms);
30+
public function mapDataToForms($viewData, $forms);
2831

2932
/**
30-
* Maps the data of a list of forms into the properties of some data.
33+
* Maps the model data of a list of children forms into the view data of their parent.
34+
*
35+
* This is the internal cascade call of FormInterface::submit for compound forms, since they
36+
* cannot be bound to any input nor the request as scalar, but their children may:
37+
*
38+
* $compoundForm->submit($arrayOfChildrenViewData)
39+
* // inside:
40+
* $childForm->submit($childViewData);
41+
* // for each entry, do the same and/or reverse transform
42+
* $this->dataMapper->mapFormsToData($compoundForm, $compoundInitialViewData)
43+
* // then reverse transform
44+
*
45+
* When a simple form is submitted the following is happening:
46+
*
47+
* $simpleForm->submit($submittedViewData)
48+
* // inside:
49+
* $this->viewData = $submittedViewData
50+
* // then reverse transform
51+
*
52+
* The model data can be an array or an object, so this second argument is always passed
53+
* by reference.
3154
*
32-
* @param FormInterface[]|\Traversable $forms A list of {@link FormInterface} instances
33-
* @param mixed $data Structured data
55+
* @param FormInterface[]|\Traversable $forms A list of {@link FormInterface} instances
56+
* @param mixed $viewData The compound form's view data that get mapped
57+
* its children model data
3458
*
3559
* @throws Exception\UnexpectedTypeException if the type of the data parameter is not supported
3660
*/
37-
public function mapFormsToData($forms, &$data);
61+
public function mapFormsToData($forms, &$viewData);
3862
}

‎src/Symfony/Component/Form/DataTransformerInterface.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/DataTransformerInterface.php
+28-13Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,35 @@ interface DataTransformerInterface
2323
/**
2424
* Transforms a value from the original representation to a transformed representation.
2525
*
26-
* This method is called on two occasions inside a form field:
26+
* This method is called when the form field is initialized with its default data, on
27+
* two occasions for two types of transformers:
2728
*
28-
* 1. When the form field is initialized with the data attached from the datasource (object or array).
29-
* 2. When data from a request is submitted using {@link Form::submit()} to transform the new input data
30-
* back into the renderable format. For example if you have a date field and submit '2009-10-10'
31-
* you might accept this value because its easily parsed, but the transformer still writes back
32-
* "2009/10/10" onto the form field (for further displaying or other purposes).
29+
* 1. Model transformers which normalize the model data.
30+
* This is mainly useful when the same form type (the same configuration)
31+
* has to handle different kind of underlying data, e.g The DateType can
32+
* deal with strings or \DateTime objects as input.
33+
*
34+
* 2. View transformers which adapt the normalized data to the view format.
35+
* a/ When the form is simple, the value returned by convention is used
36+
* directly in the view and thus can only be a string or an array. In
37+
* this case the data class should be null.
38+
*
39+
* b/ When the form is compound the returned value should be an array or
40+
* an object to be mapped to the children. Each property of the compound
41+
* data will be used as model data by each child and will be transformed
42+
* too. In this case data class should be the class of the object, or null
43+
* when it is an array.
44+
*
45+
* All transformers are called in a configured order from model data to view value.
46+
* At the end of this chain the view data will be validated against the data class
47+
* setting.
3348
*
3449
* This method must be able to deal with empty values. Usually this will
3550
* be NULL, but depending on your implementation other empty values are
3651
* possible as well (such as empty strings). The reasoning behind this is
37-
* that value transformers must be chainable. If the transform() method
38-
* of the first value transformer outputs NULL, the second value transformer
39-
* must be able to process that value.
40-
*
41-
* By convention, transform() should return an empty string if NULL is
42-
* passed.
52+
* that data transformers must be chainable. If the transform() method
53+
* of the first data transformer outputs NULL, the second must be able to
54+
* process that value.
4355
*
4456
* @param mixed $value The value in the original representation
4557
*
@@ -54,7 +66,10 @@ public function transform($value);
5466
* representation.
5567
*
5668
* This method is called when {@link Form::submit()} is called to transform the requests tainted data
57-
* into an acceptable format for your data processing/model layer.
69+
* into an acceptable format.
70+
*
71+
* The same transformers are called in the reverse order so the responsibility is to
72+
* return one of the types that would be expected as input of transform().
5873
*
5974
* This method must be able to deal with empty values. Usually this will
6075
* be an empty string, but depending on your implementation other empty

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.