Exemplo n.º 1
0
 /**
  * Render a dump for a string value.
  *
  * @param Model $model
  *   The data we are analysing.
  *
  * @return string
  *   The rendered markup.
  */
 public function analyseString(Model $model)
 {
     $json = array();
     $json['type'] = 'string';
     $data = $model->getData();
     // Extra ?
     if (strlen($data) > 50) {
         $cut = substr($this->storage->encodeString($data), 0, 50) . '. . .';
         $model->hasExtras();
     } else {
         $cut = $this->storage->encodeString($data);
     }
     $json['encoding'] = @mb_detect_encoding($data);
     // We need to take care for mixed encodings here.
     $json['length'] = (string) ($strlen = @mb_strlen($data, $json['encoding']));
     if ($strlen === false) {
         // Looks like we have a mixed encoded string.
         $json['length'] = '~ ' . strlen($data);
         $strlen = ' broken encoding ' . $json['length'];
         $json['encoding'] = 'broken';
     }
     $data = $this->storage->encodeString($data);
     $model->setData($data)->setNormal($cut)->setType($model->getAdditional() . 'string' . ' ' . $strlen)->setJson($json);
     // Check if this is a possible callback.
     // We are not going to analyse this further, because modern systems
     // do not use these anymore.
     if (is_callable($data)) {
         $model->setIsCallback(true);
     }
     return $this->storage->render->renderSingleChild($model);
 }