Пример #1
0
 public function dumpLog(\Twig_Environment $env, $message, Data $context)
 {
     $message = twig_escape_filter($env, $message);
     if (false === strpos($message, '{')) {
         return '<span class="dump-inline">' . $message . '</span>';
     }
     $replacements = array();
     foreach ($context->getRawData()[1] as $k => $v) {
         $v = '{' . twig_escape_filter($env, $k) . '}';
         $replacements['&quot;' . $v . '&quot;'] = $replacements[$v] = $this->dumpData($env, $context->seek($k));
     }
     return '<span class="dump-inline">' . strtr($message, $replacements) . '</span>';
 }
Пример #2
0
 /**
  * Dumps a Data object.
  *
  * @param Data                          $data   A Data object.
  * @param callable|resource|string|null $output A line dumper callable, an opened stream or an output path.
  */
 public function dump(Data $data, $output = null)
 {
     $exception = null;
     if ($output) {
         $prevOutput = $this->setOutput($output);
     }
     try {
         $data->dump($this);
         $this->dumpLine(-1);
     } catch (\Exception $exception) {
         // Re-thrown below
     }
     if ($output) {
         $this->setOutput($prevOutput);
     }
     if (null !== $exception) {
         throw $exception;
     }
 }
Пример #3
0
 /**
  * Dumps a Data object.
  *
  * @param Data          $data       A Data object.
  * @param callable|null $lineDumper A callback for writing dump's lines.
  */
 public function dump(Data $data, $lineDumper = null)
 {
     $exception = null;
     if ($lineDumper) {
         $prevLineDumper = $this->setLineDumper($lineDumper);
     }
     try {
         $data->dump($this);
         $this->dumpLine(-1);
     } catch (\Exception $exception) {
         // Re-thrown below
     }
     if ($lineDumper) {
         $this->setLineDumper($prevLineDumper);
     }
     if (null !== $exception) {
         throw $exception;
     }
 }
Пример #4
0
 /**
  * Dumps a Data object.
  *
  * @param Data                               $data   A Data object
  * @param callable|resource|string|true|null $output A line dumper callable, an opened stream, an output path or true to return the dump
  *
  * @return string|null The dump as string when $output is true
  */
 public function dump(Data $data, $output = null)
 {
     if ($returnDump = true === $output) {
         $output = fopen('php://memory', 'r+b');
     }
     if ($output) {
         $prevOutput = $this->setOutput($output);
     }
     try {
         $data->dump($this);
         $this->dumpLine(-1);
         if ($returnDump) {
             $result = stream_get_contents($output, -1, 0);
             fclose($output);
             return $result;
         }
     } finally {
         if ($output) {
             $this->setOutput($prevOutput);
         }
     }
 }
 public function dump(Data $data)
 {
     $rawData = $data->getRawData();
     echo '+' . $rawData[0];
 }
 /**
  * {@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);
 }
Пример #7
0
 /**
  * Dumps a Data object.
  *
  * @param Data                          $data   A Data object
  * @param callable|resource|string|null $output A line dumper callable, an opened stream or an output path
  */
 public function dump(Data $data, $output = null)
 {
     if ($output) {
         $prevOutput = $this->setOutput($output);
     }
     try {
         $data->dump($this);
         $this->dumpLine(-1);
     } finally {
         if ($output) {
             $this->setOutput($prevOutput);
         }
     }
 }
Пример #8
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) . ' ';
         }
     }
 }