Вход Регистрация
Файл: symfony-2.7/src/Symfony/Component/VarDumper/Caster/ExceptionCaster.php
Строк: 95
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace SymfonyComponentVarDumperCaster;

use 
SymfonyComponentVarDumperExceptionThrowingCasterException;
use 
SymfonyComponentVarDumperClonerStub;

/**
 * Casts common Exception classes to array representation.
 *
 * @author Nicolas Grekas <p@tchwork.com>
 */
class ExceptionCaster
{
    public static 
$traceArgs true;
    public static 
$errorTypes = array(
        
E_DEPRECATED => 'E_DEPRECATED',
        
E_USER_DEPRECATED => 'E_USER_DEPRECATED',
        
E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR',
        
E_ERROR => 'E_ERROR',
        
E_WARNING => 'E_WARNING',
        
E_PARSE => 'E_PARSE',
        
E_NOTICE => 'E_NOTICE',
        
E_CORE_ERROR => 'E_CORE_ERROR',
        
E_CORE_WARNING => 'E_CORE_WARNING',
        
E_COMPILE_ERROR => 'E_COMPILE_ERROR',
        
E_COMPILE_WARNING => 'E_COMPILE_WARNING',
        
E_USER_ERROR => 'E_USER_ERROR',
        
E_USER_WARNING => 'E_USER_WARNING',
        
E_USER_NOTICE => 'E_USER_NOTICE',
        
E_STRICT => 'E_STRICT',
    );

    public static function 
castException(Exception $e, array $aStub $stub$isNested)
    {
        
$trace $a["Exceptiontrace"];
        unset(
$a["Exceptiontrace"]); // Ensures the trace is always last

        
static::filterTrace($trace, static::$traceArgs);

        if (
null !== $trace) {
            
$a["Exceptiontrace"] = $trace;
        }
        if (empty(
$a["Exceptionprevious"])) {
            unset(
$a["Exceptionprevious"]);
        }
        unset(
$a["Exceptionstring"], $a["+xdebug_message"], $a["+__destructorException"]);

        return 
$a;
    }

    public static function 
castErrorException(ErrorException $e, array $aStub $stub$isNested)
    {
        if (isset(
$a[$s "*severity"], self::$errorTypes[$a[$s]])) {
            
$a[$s] = new ConstStub(self::$errorTypes[$a[$s]], $a[$s]);
        }

        return 
$a;
    }

    public static function 
castThrowingCasterException(ThrowingCasterException $e, array $aStub $stub$isNested)
    {
        
$b = (array) $a["Exceptionprevious"];

        
array_splice($b["Exceptiontrace"], count($a["Exceptiontrace"]));

        
$t = static::$traceArgs;
        static::
$traceArgs false;
        
$b = static::castException($a["Exceptionprevious"], $b$stub$isNested);
        static::
$traceArgs $t;

        if (empty(
$a["*message"])) {
            
$a["*message"] = "Unexpected exception thrown from a caster: ".get_class($a["Exceptionprevious"]);
        }

        if (isset(
$b["*message"])) {
            
$a["~message"] = $b["*message"];
        }
        if (isset(
$b["*file"])) {
            
$a["~file"] = $b["*file"];
        }
        if (isset(
$b["*line"])) {
            
$a["~line"] = $b["*line"];
        }
        if (isset(
$b["Exceptiontrace"])) {
            
$a["~trace"] = $b["Exceptiontrace"];
        }

        unset(
$a["Exceptiontrace"], $a["Exceptionprevious"], $a["*code"], $a["*file"], $a["*line"]);

        return 
$a;
    }

    public static function 
filterTrace(&$trace$dumpArgs$offset 0)
    {
        if (
$offset || empty($trace[$offset])) {
            return 
$trace null;
        }

        
$t $trace[$offset];

        if (empty(
$t['class']) && isset($t['function'])) {
            if (
'user_error' === $t['function'] || 'trigger_error' === $t['function']) {
                ++
$offset;
            }
        }

        if (
$offset) {
            
array_splice($trace0$offset);
        }

        foreach (
$trace as &$t) {
            
$t = array(
                
'call' => (isset($t['class']) ? $t['class'].$t['type'] : '').$t['function'].'()',
                
'file' => isset($t['line']) ? "{$t['file']}:{$t['line']}'',
                
'args' => &$t['args'],
            );

            if (!isset(
$t['args']) || !$dumpArgs) {
                unset(
$t['args']);
            }
        }
    }
}
Онлайн: 1
Реклама