ChoiceTrait.php 616 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace DeviceBundle\Utils;
  3. trait ChoiceTrait
  4. {
  5. /**
  6. * @return array
  7. */
  8. static function getConstants()
  9. {
  10. $oClass = new \ReflectionClass(__CLASS__);
  11. return $oClass->getConstants();
  12. }
  13. /**
  14. * Retorna un array con todas las constantes de la clase
  15. * para utilizar en campos de tipo choice en forms
  16. *
  17. * @return array
  18. */
  19. public static function getChoices()
  20. {
  21. $choices = array();
  22. foreach (self::getConstants() as $constant) {
  23. $choices[$constant] = $constant;
  24. }
  25. return $choices;
  26. }
  27. }