Esempio n. 1
0
 /**
  * Guesses a field class name for a given constraint
  * @param object $annot The annotation to guess for
  * @return TypeGuess The guessed field class and options
  */
 public function guessTypeForAnnotation($annot, $class, $property)
 {
     switch (get_class($annot)) {
         case 'Symfony\\Component\\Validator\\Constraints\\Choice':
             $options = null;
             if ($annot->choices && is_array($annot->choices)) {
                 $options = $annot->choices;
             } else {
                 if (is_string($annot->callback)) {
                     $callback = $annot->callback;
                     $options = call_user_func([$class, $callback]);
                 } else {
                     if (is_array($annot->callback)) {
                         $options = call_user_func($annot->callback);
                     }
                 }
             }
             if (is_array($options)) {
                 if (ArrayUtil::isAssociative($options)) {
                     $options = array_combine(array_values($options), array_keys($options));
                 } else {
                     $values = array_values($options);
                     $options = array_combine($values, $values);
                 }
                 return new TypeGuess('choice', ['choices' => $options], Guess::HIGH_CONFIDENCE);
             }
     }
     return null;
 }