IntlCallbackChoiceLoader.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. * Callback choice loader optimized for Intl choice types.
  13. *
  14. * @author Jules Pietri <jules@heahprod.com>
  15. * @author Yonel Ceruto <yonelceruto@gmail.com>
  16. */
  17. class IntlCallbackChoiceLoader extends CallbackChoiceLoader
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public function loadChoicesForValues(array $values, callable $value = null)
  23. {
  24. return parent::loadChoicesForValues(array_filter($values), $value);
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function loadValuesForChoices(array $choices, callable $value = null)
  30. {
  31. $choices = array_filter($choices);
  32. // If no callable is set, choices are the same as values
  33. if (null === $value) {
  34. return $choices;
  35. }
  36. return parent::loadValuesForChoices($choices, $value);
  37. }
  38. }