CallbackChoiceLoader.php 806 B

1234567891011121314151617181920212223242526272829303132333435
  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. /**
  12. * Loads an {@link ArrayChoiceList} instance from a callable returning iterable choices.
  13. *
  14. * @author Jules Pietri <jules@heahprod.com>
  15. */
  16. class CallbackChoiceLoader extends AbstractChoiceLoader
  17. {
  18. private $callback;
  19. /**
  20. * @param callable $callback The callable returning iterable choices
  21. */
  22. public function __construct(callable $callback)
  23. {
  24. $this->callback = $callback;
  25. }
  26. protected function loadChoices(): iterable
  27. {
  28. return ($this->callback)();
  29. }
  30. }