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

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.     public function createListFromChoices(iterable $choices, callable $value null, callable $filter null): ChoiceListInterface;
  33.     /**
  34.      * Creates a choice list that is loaded with the given loader.
  35.      *
  36.      * Optionally, a callable can be passed for generating the choice values.
  37.      * The callable receives the choice as only argument.
  38.      * Null may be passed when the choice list contains the empty value.
  39.      *
  40.      * @param callable|null $filter The callable filtering the choices
  41.      */
  42.     public function createListFromLoader(ChoiceLoaderInterface $loader, callable $value null, callable $filter null): ChoiceListInterface;
  43.     /**
  44.      * Creates a view for the given choice list.
  45.      *
  46.      * Callables may be passed for all optional arguments. The callables receive
  47.      * the choice as first and the array key as the second argument.
  48.      *
  49.      *  * The callable for the label and the name should return the generated
  50.      *    label/choice name.
  51.      *  * The callable for the preferred choices should return true or false,
  52.      *    depending on whether the choice should be preferred or not.
  53.      *  * The callable for the grouping should return the group name or null if
  54.      *    a choice should not be grouped.
  55.      *  * The callable for the attributes should return an array of HTML
  56.      *    attributes that will be inserted in the tag of the choice.
  57.      *
  58.      * If no callable is passed, the labels will be generated from the choice
  59.      * keys. The view indices will be generated using an incrementing integer
  60.      * by default.
  61.      *
  62.      * The preferred choices can also be passed as array. Each choice that is
  63.      * contained in that array will be marked as preferred.
  64.      *
  65.      * The attributes can be passed as multi-dimensional array. The keys should
  66.      * match the keys of the choices. The values should be arrays of HTML
  67.      * attributes that should be added to the respective choice.
  68.      *
  69.      * @param array|callable|null $preferredChoices           The preferred choices
  70.      * @param callable|false|null $label                      The callable generating the choice labels;
  71.      *                                                        pass false to discard the label
  72.      * @param array|callable|null $attr                       The callable generating the HTML attributes
  73.      * @param array|callable      $labelTranslationParameters The parameters used to translate the choice labels
  74.      */
  75.     public function createView(ChoiceListInterface $list, array|callable $preferredChoices null, callable|false $label null, callable $index null, callable $groupBy null, array|callable $attr null, array|callable $labelTranslationParameters = []): ChoiceListView;
  76. }