public static function Debug::export

Export

Parameters

mixed $var:

int $maxDepth:

Return value

mixed

3 calls to Debug::export()
Debug::dump in drupal/core/vendor/doctrine/common/lib/Doctrine/Common/Util/Debug.php
Prints a dump of the public, protected and private properties of $var.
DebugTest::testExportDateTime in drupal/core/vendor/doctrine/common/tests/Doctrine/Tests/Common/Util/DebugTest.php
DebugTest::testExportObject in drupal/core/vendor/doctrine/common/tests/Doctrine/Tests/Common/Util/DebugTest.php

File

drupal/core/vendor/doctrine/common/lib/Doctrine/Common/Util/Debug.php, line 76

Class

Debug
Static class containing most used debug methods.

Namespace

Doctrine\Common\Util

Code

public static function export($var, $maxDepth) {
  $return = null;
  $isObj = is_object($var);
  if ($isObj && in_array('Doctrine\\Common\\Collections\\Collection', class_implements($var))) {
    $var = $var
      ->toArray();
  }
  if ($maxDepth) {
    if (is_array($var)) {
      $return = array();
      foreach ($var as $k => $v) {
        $return[$k] = self::export($v, $maxDepth - 1);
      }
    }
    else {
      if ($isObj) {
        $return = new \stdclass();
        if ($var instanceof \DateTime) {
          $return->__CLASS__ = "DateTime";
          $return->date = $var
            ->format('c');
          $return->timezone = $var
            ->getTimeZone()
            ->getName();
        }
        else {
          $reflClass = ClassUtils::newReflectionObject($var);
          $return->__CLASS__ = ClassUtils::getClass($var);
          if ($var instanceof \Doctrine\Common\Persistence\Proxy) {
            $return->__IS_PROXY__ = true;
            $return->__PROXY_INITIALIZED__ = $var
              ->__isInitialized();
          }
          foreach ($reflClass
            ->getProperties() as $reflProperty) {
            $name = $reflProperty
              ->getName();
            $reflProperty
              ->setAccessible(true);
            $return->{$name} = self::export($reflProperty
              ->getValue($var), $maxDepth - 1);
          }
        }
      }
      else {
        $return = $var;
      }
    }
  }
  else {
    $return = is_object($var) ? get_class($var) : (is_array($var) ? 'Array(' . count($var) . ')' : $var);
  }
  return $return;
}