コード例 #1
0
ファイル: XmlResponse.php プロジェクト: tweedegolf/okoabundle
 /**
  * Transform an associative array or associative iterable to a xml document.
  * @param mixed $iterable
  * @param DOMElement $element
  * @param DOMDocument $document
  * @return void
  */
 public function assocToXml($iterable, DOMElement $element, DOMDocument $document)
 {
     foreach ($iterable as $key => $item) {
         $iterable = is_array($item) || $item instanceof Iterator;
         if ($iterable && ArrayUtil::isIndexed($item)) {
             $key = StringUtil::pluralize($key);
         }
         if (is_int($key)) {
             $key = $this->numNodePrefix . $key;
         }
         $node = $document->createElement($key);
         $element->appendChild($node);
         $this->toXml($item, $node, $document);
     }
 }
コード例 #2
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;
 }