Skip to content

Commit 57cc531

Browse files
committed
[Form] Improved PHPDocs of choice lists
1 parent 9e7e2af commit 57cc531

File tree

3 files changed

+51
-7
lines changed

3 files changed

+51
-7
lines changed

src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,16 @@
1717
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
1818

1919
/**
20-
* Base class for choice list implementations.
20+
* A choice list for choices of arbitrary data types.
21+
*
22+
* Choices and labels are passed in two arrays. The indices of the choices
23+
* and the labels should match.
24+
*
25+
* <code>
26+
* $choices = array(true, false);
27+
* $labels = array('Agree', 'Disagree');
28+
* $choiceList = new ChoiceList($choices, $labels);
29+
* </code>
2130
*
2231
* @author Bernhard Schussek <bschussek@gmail.<com>
2332
*/

src/Symfony/Component/Form/Extension/Core/ChoiceList/ObjectChoiceList.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,17 @@
1717
use Symfony\Component\Form\Exception\InvalidPropertyException;
1818

1919
/**
20-
* A choice list that can store object choices.
20+
* A choice list for object choices.
2121
*
2222
* Supports generation of choice labels, choice groups, choice values and
23-
* choice indices by introspecting the properties of the object (or
24-
* associated objects).
23+
* choice indices by calling getters of the object (or associated objects).
24+
*
25+
* <code>
26+
* $choices = array($user1, $user2);
27+
*
28+
* // call getName() to determine the choice labels
29+
* $choiceList = new ObjectChoiceList($choices, 'name');
30+
* </code>
2531
*
2632
* @author Bernhard Schussek <bschussek@gmail.com>
2733
*/

src/Symfony/Component/Form/Extension/Core/ChoiceList/SimpleChoiceList.php

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,39 @@
1515
use Symfony\Component\Form\Exception\UnexpectedTypeException;
1616

1717
/**
18-
* A choice list that can store any choices that are allowed as PHP array keys.
18+
* A choice list for choices of type string or integer.
1919
*
20-
* The value strategy of simple choice lists is fixed to ChoiceList::COPY_CHOICE,
21-
* since array keys are always valid choice values.
20+
* Choices and their associated labels can be passed in a single array. Since
21+
* choices are passed as array keys, only strings or integer choices are
22+
* allowed.
23+
*
24+
* <code>
25+
* $choiceList = new SimpleChoiceList(array(
26+
* 'creditcard' => 'Credit card payment',
27+
* 'cash' => 'Cash payment',
28+
* ));
29+
* </code>
30+
*
31+
* The default value generation strategy is `ChoiceList::COPY_CHOICE`, because
32+
* choice values must be scalar, and the choices passed to this choice list
33+
* are guaranteed to be scalar.
34+
*
35+
* The default index generation strategy is `ChoiceList::GENERATE`, so that
36+
* your choices can also contain values that are illegal as indices. If your
37+
* choices are guaranteed to start with a letter, digit or underscore and only
38+
* contain letters, digits, underscores, hyphens and colons, you can set the
39+
* strategy to `ChoiceList::COPY_CHOICE` instead.
40+
*
41+
* <code>
42+
* $choices = array(
43+
* 'creditcard' => 'Credit card payment',
44+
* 'cash' => 'Cash payment',
45+
* );
46+
*
47+
* // value generation: COPY_CHOICE (the default)
48+
* // index generation: COPY_CHOICE (custom)
49+
* $choiceList = new SimpleChoiceList($choices, array(), ChoiceList::COPY_CHOICE, ChoiceList::COPY_CHOICE);
50+
* </code>
2251
*
2352
* @author Bernhard Schussek <bschussek@gmail.com>
2453
*/

0 commit comments

Comments
 (0)