/**
  * {@inheritdoc}
  */
 public function dumpScalar(Cursor $cursor, $type, $value)
 {
     $this->dumpKey($cursor);
     $style = 'const';
     $attr = array();
     switch ($type) {
         case 'integer':
             $style = 'num';
             break;
         case 'double':
             $style = 'num';
             switch (true) {
                 case INF === $value:
                     $value = 'INF';
                     break;
                 case -INF === $value:
                     $value = '-INF';
                     break;
                 case is_nan($value):
                     $value = 'NAN';
                     break;
                 default:
                     $value = (string) $value;
                     if (false === strpos($value, $this->decimalPoint)) {
                         $value .= $this->decimalPoint . '0';
                     }
                     break;
             }
             break;
         case 'NULL':
             $value = 'null';
             break;
         case 'boolean':
             $value = $value ? 'true' : 'false';
             break;
         default:
             $attr['value'] = isset($value[0]) && !preg_match('//u', $value) ? Data::utf8Encode($value) : $value;
             $value = isset($type[0]) && !preg_match('//u', $type) ? Data::utf8Encode($type) : $type;
             break;
     }
     $this->line .= $this->style($style, $value, $attr);
     $this->dumpLine($cursor->depth);
 }
Exemple #2
0
 /**
  * Dumps a key in a hash structure.
  *
  * @param Cursor $cursor The Cursor position in the dump.
  */
 protected function dumpKey(Cursor $cursor)
 {
     if (null !== ($key = $cursor->hashKey)) {
         if ($bin = isset($key[0]) && !preg_match('//u', $key)) {
             $key = Data::utf8Encode($key);
             $bin = 'b';
         }
         switch ($cursor->hashType) {
             default:
             case Cursor::HASH_INDEXED:
             case Cursor::HASH_ASSOC:
                 if (is_int($key)) {
                     $this->line .= $this->style('meta', $key) . ' => ';
                 } else {
                     $this->line .= $bin . '"' . $this->style('meta', $key) . '" => ';
                 }
                 break;
             case Cursor::HASH_RESOURCE:
                 $key = "~" . $key;
                 // No break;
             // No break;
             case Cursor::HASH_OBJECT:
                 if (!isset($key[0]) || "" !== $key[0]) {
                     $this->line .= $bin . $this->style('public', $key) . ': ';
                 } elseif (0 < strpos($key, "", 1)) {
                     $key = explode("", substr($key, 1), 2);
                     switch ($key[0]) {
                         case '+':
                             // User inserted keys
                             $this->line .= $bin . '"' . $this->style('public', $key[1]) . '": ';
                             break 2;
                         case '~':
                             $style = 'meta';
                             break;
                         case '*':
                             $style = 'protected';
                             break;
                         default:
                             $style = 'private';
                             break;
                     }
                     $this->line .= $bin . $this->style($style, $key[1]) . ': ';
                 } else {
                     // This case should not happen
                     $this->line .= $bin . '"' . $this->style('private', $key) . '": ';
                 }
                 break;
         }
         if (false !== $cursor->hardRefTo) {
             $this->line .= $this->style('ref', '&' . $cursor->hardRefTo) . ' ';
         }
     }
 }