ChoiceLoaderInterface.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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\Loader;
  11. use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
  12. /**
  13. * Loads a choice list.
  14. *
  15. * The methods {@link loadChoicesForValues()} and {@link loadValuesForChoices()}
  16. * can be used to load the list only partially in cases where a fully-loaded
  17. * list is not necessary.
  18. *
  19. * @author Bernhard Schussek <bschussek@gmail.com>
  20. */
  21. interface ChoiceLoaderInterface
  22. {
  23. /**
  24. * Loads a list of choices.
  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 $value The callable which generates the values
  31. * from choices
  32. *
  33. * @return ChoiceListInterface The loaded choice list
  34. */
  35. public function loadChoiceList(callable $value = null);
  36. /**
  37. * Loads the choices corresponding to the given values.
  38. *
  39. * The choices are returned with the same keys and in the same order as the
  40. * corresponding values in the given array.
  41. *
  42. * Optionally, a callable can be passed for generating the choice values.
  43. * The callable receives the choice as only argument.
  44. * Null may be passed when the choice list contains the empty value.
  45. *
  46. * @param string[] $values An array of choice values. Non-existing
  47. * values in this array are ignored
  48. * @param callable|null $value The callable generating the choice values
  49. *
  50. * @return array An array of choices
  51. */
  52. public function loadChoicesForValues(array $values, callable $value = null);
  53. /**
  54. * Loads the values corresponding to the given choices.
  55. *
  56. * The values are returned with the same keys and in the same order as the
  57. * corresponding choices in the given array.
  58. *
  59. * Optionally, a callable can be passed for generating the choice values.
  60. * The callable receives the choice as only argument.
  61. * Null may be passed when the choice list contains the empty value.
  62. *
  63. * @param array $choices An array of choices. Non-existing choices in
  64. * this array are ignored
  65. * @param callable|null $value The callable generating the choice values
  66. *
  67. * @return string[] An array of choice values
  68. */
  69. public function loadValuesForChoices(array $choices, callable $value = null);
  70. }