vendor/symfony/form/ChoiceList/Factory/ChoiceListFactoryInterface.php line 38

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\Form\ChoiceList\Factory;
  11. use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
  12. use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
  13. use Symfony\Component\Form\ChoiceList\View\ChoiceListView;
  14. /**
  15.  * Creates {@link ChoiceListInterface} instances.
  16.  *
  17.  * @author Bernhard Schussek <bschussek@gmail.com>
  18.  */
  19. interface ChoiceListFactoryInterface
  20. {
  21.     /**
  22.      * Creates a choice list for the given choices.
  23.      *
  24.      * The choices should be passed in the values of the choices array.
  25.      *
  26.      * Optionally, a callable can be passed for generating the choice values.
  27.      * The callable receives the choice as only argument.
  28.      * Null may be passed when the choice list contains the empty value.
  29.      *
  30.      * @param callable|null $filter The callable filtering the choices
  31.      *
  32.      * @return ChoiceListInterface
  33.      */
  34.     public function createListFromChoices(iterable $choices, callable $value null/* , callable $filter = null */);
  35.     /**
  36.      * Creates a choice list that is loaded with the given loader.
  37.      *
  38.      * Optionally, a callable can be passed for generating the choice values.
  39.      * The callable receives the choice as only argument.
  40.      * Null may be passed when the choice list contains the empty value.
  41.      *
  42.      * @param callable|null $filter The callable filtering the choices
  43.      *
  44.      * @return ChoiceListInterface
  45.      */
  46.     public function createListFromLoader(ChoiceLoaderInterface $loader, callable $value null/* , callable $filter = null */);
  47.     /**
  48.      * Creates a view for the given choice list.
  49.      *
  50.      * Callables may be passed for all optional arguments. The callables receive
  51.      * the choice as first and the array key as the second argument.
  52.      *
  53.      *  * The callable for the label and the name should return the generated
  54.      *    label/choice name.
  55.      *  * The callable for the preferred choices should return true or false,
  56.      *    depending on whether the choice should be preferred or not.
  57.      *  * The callable for the grouping should return the group name or null if
  58.      *    a choice should not be grouped.
  59.      *  * The callable for the attributes should return an array of HTML
  60.      *    attributes that will be inserted in the tag of the choice.
  61.      *
  62.      * If no callable is passed, the labels will be generated from the choice
  63.      * keys. The view indices will be generated using an incrementing integer
  64.      * by default.
  65.      *
  66.      * The preferred choices can also be passed as array. Each choice that is
  67.      * contained in that array will be marked as preferred.
  68.      *
  69.      * The attributes can be passed as multi-dimensional array. The keys should
  70.      * match the keys of the choices. The values should be arrays of HTML
  71.      * attributes that should be added to the respective choice.
  72.      *
  73.      * @param array|callable|null $preferredChoices           The preferred choices
  74.      * @param callable|false|null $label                      The callable generating the choice labels;
  75.      *                                                        pass false to discard the label
  76.      * @param array|callable|null $attr                       The callable generating the HTML attributes
  77.      * @param array|callable      $labelTranslationParameters The parameters used to translate the choice labels
  78.      *
  79.      * @return ChoiceListView
  80.      */
  81.     public function createView(ChoiceListInterface $list$preferredChoices null$label null, callable $index null, callable $groupBy null$attr null/* , $labelTranslationParameters = [] */);
  82. }