You are here

class VarDumpService in Development Environment 8

The VarDumpService class.

Hierarchy

Expanded class hierarchy of VarDumpService

1 string reference to 'VarDumpService'
development_environment.services.yml in ./development_environment.services.yml
development_environment.services.yml

File

src/Service/VarDumpService.php, line 8

Namespace

Drupal\development_environment\Service
View source
class VarDumpService implements VarDumpServiceInterface {

  /**
   * {@inheritdoc}
   */
  public function varDump($var, $return = FALSE, $html = FALSE, $level = 0) {
    $spaces = "";
    $space = $html ? " " : " ";
    $newline = $html ? "<br />" : "\n";
    for ($i = 1; $i <= 4; $i++) {
      $spaces .= $space;
    }
    $tabs = $spaces;
    for ($i = 1; $i <= $level; $i++) {
      $tabs .= $spaces;
    }
    if (is_array($var)) {
      $title = "Array";
    }
    elseif (is_object($var)) {
      $title = get_class($var) . " Object";
    }
    $output = $title . $newline . $newline;
    foreach ($var as $key => $value) {
      if (is_array($value) || is_object($value)) {
        $level++;
        $value = $this
          ->varDump($value, TRUE, $html, $level);
        $level--;
      }
      $output .= $tabs . "[" . $key . "] => " . $value . $newline;
    }
    if ($return) {
      return $output;
    }
    else {
      echo $output;
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
VarDumpService::varDump public function Dumps the details of a variable. Overrides VarDumpServiceInterface::varDump