Exemple #1
0
 /**
  *
  */
 protected function encodeArrayToXML($data, $parent, $pretty_print = false)
 {
     $content = '';
     $parent_sing = Inflector::singularize($parent);
     $numeric_keys = Arrays::isNumericallyKeyed($data);
     if ($pretty_print !== false) {
         $prefix = str_repeat('  ', $pretty_print);
     } else {
         $prefix = '';
     }
     foreach ($data as $key => $value) {
         $key = $numeric_keys ? $parent_sing : $key;
         $content .= $prefix . '<' . htmlspecialchars($key) . '>';
         switch (true) {
             case is_array($value):
             case is_object($value):
                 if ($pretty_print !== false) {
                     $content .= "\n";
                 }
                 $content .= $this->encodeArrayToXML($value, $key, $pretty_print !== false ? $pretty_print + 1 : false) . $prefix;
                 break;
             case is_bool($value):
                 $content .= $value ? 'true' : 'false';
                 break;
             case is_string($value):
             case is_numeric($value):
             default:
                 $content .= htmlspecialchars($value);
                 break;
         }
         $content .= '</' . htmlspecialchars($key) . '>';
         if ($pretty_print !== false) {
             $content .= "\n";
         }
     }
     return $content;
 }
Exemple #2
0
 /**
  * @dataProvider  isNumericallyKeyedProvider
  */
 public function testIsNumericallyKeyed($expected, $input)
 {
     $this->assertSame($expected, Arrays::isNumericallyKeyed($input));
 }