Doctrine\Common\Util\Debug::export PHP Method

export() public static method

public static export ( mixed $var, integer $maxDepth ) : mixed
$var mixed
$maxDepth integer
return mixed
    public static function export($var, $maxDepth)
    {
        $return = null;
        $isObj = is_object($var);
        if ($var instanceof Collection) {
            $var = $var->toArray();
        }
        if (!$maxDepth) {
            return is_object($var) ? get_class($var) : (is_array($var) ? 'Array(' . count($var) . ')' : $var);
        }
        if (is_array($var)) {
            $return = [];
            foreach ($var as $k => $v) {
                $return[$k] = self::export($v, $maxDepth - 1);
            }
            return $return;
        }
        if (!$isObj) {
            return $var;
        }
        $return = new \stdclass();
        if ($var instanceof \DateTimeInterface) {
            $return->__CLASS__ = get_class($var);
            $return->date = $var->format('c');
            $return->timezone = $var->getTimezone()->getName();
            return $return;
        }
        $return->__CLASS__ = ClassUtils::getClass($var);
        if ($var instanceof Proxy) {
            $return->__IS_PROXY__ = true;
            $return->__PROXY_INITIALIZED__ = $var->__isInitialized();
        }
        if ($var instanceof \ArrayObject || $var instanceof \ArrayIterator) {
            $return->__STORAGE__ = self::export($var->getArrayCopy(), $maxDepth - 1);
        }
        return self::fillReturnWithClassAttributes($var, $return, $maxDepth);
    }

Usage Example

Ejemplo n.º 1
0
 public static function dump($entity, $maxDepth = 1, $toHtml = true)
 {
     $output = print_r(Debug::export($entity, $maxDepth), true);
     if ($toHtml) {
         echo "<pre>{$output}</pre>";
     } else {
         echo $output;
     }
 }
All Usage Examples Of Doctrine\Common\Util\Debug::export