Class yii\debug\FlattenException

Inheritanceyii\debug\FlattenException
Available since extension's version2.0.10
Source Code https://github.com/yiisoft/yii2-debug/blob/master/src/FlattenException.php

FlattenException wraps a PHP Exception to be able to serialize it.

Implements the Throwable interface Basically, this class removes all objects from the trace. Ported from Symfony components @link https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Debug/Exception/FlattenException.php

Protected Properties

Hide inherited properties

Property Type Description Defined By

Public Methods

Hide inherited methods

Method Description Defined By
__construct() FlattenException constructor. yii\debug\FlattenException
__toString() String representation of the exception yii\debug\FlattenException
getClass() yii\debug\FlattenException
getCode() Gets the Exception code yii\debug\FlattenException
getFile() Gets the file in which the exception occurred yii\debug\FlattenException
getLine() Gets the line in which the exception occurred yii\debug\FlattenException
getMessage() Gets the Exception message yii\debug\FlattenException
getPrevious() Returns previous Exception yii\debug\FlattenException
getTrace() Gets the stack trace yii\debug\FlattenException
getTraceAsString() Gets the stack trace as a string yii\debug\FlattenException

Property Details

Hide inherited properties

$code protected property
protected mixed|integer $code null
$file protected property
protected string $file null
$line protected property
protected integer $line null
$message protected property
protected string $message null

Method Details

Hide inherited methods

__construct() public method

FlattenException constructor.

public void __construct ( Exception $exception )
$exception Exception

                public function __construct(\Exception $exception)
{
    $this->setMessage($exception->getMessage());
    $this->setCode($exception->getCode());
    $this->setFile($exception->getFile());
    $this->setLine($exception->getLine());
    $this->setTrace($exception->getTrace());
    $this->setToString($exception->__toString());
    $this->setClass(get_class($exception));
    $previous = $exception->getPrevious();
    if ($previous instanceof \Exception) {
        $this->setPrevious(new self($previous));
    }
}

            
__toString() public method

String representation of the exception

public string __toString ( )
return string

The string representation of the exception.

                public function __toString()
{
    return $this->_toString;
}

            
getClass() public method

public string getClass ( )
return string

The name of the class in which the exception was created.

                public function getClass()
{
    return $this->_class;
}

            
getCode() public method

Gets the Exception code

public mixed|integer getCode ( )
return mixed|integer

The exception code as integer.

                public function getCode()
{
    return $this->code;
}

            
getFile() public method

Gets the file in which the exception occurred

public string getFile ( )
return string

The filename in which the exception was created.

                public function getFile()
{
    return $this->file;
}

            
getLine() public method

Gets the line in which the exception occurred

public integer getLine ( )
return integer

The line number where the exception was created.

                public function getLine()
{
    return $this->line;
}

            
getMessage() public method

Gets the Exception message

public string getMessage ( )
return string

The Exception message as a string.

                public function getMessage()
{
    return $this->message;
}

            
getPrevious() public method

Returns previous Exception

public yii\debug\FlattenException getPrevious ( )
return yii\debug\FlattenException

The previous FlattenException if available or null otherwise.

                public function getPrevious()
{
    return $this->_previous;
}

            
getTrace() public method

Gets the stack trace

public array getTrace ( )
return array

The Exception stack trace as an array.

                public function getTrace()
{
    return $this->_trace;
}

            
getTraceAsString() public method

Gets the stack trace as a string

public string getTraceAsString ( )
return string

The Exception stack trace as a string.

                public function getTraceAsString()
{
    $remove = "Stack trace:\n";
    $len = strpos($this->_toString, $remove);
    if ($len === false) {
        return '';
    }
    return substr($this->_toString, $len + strlen($remove));
}

            
setClass() protected method

protected void setClass ( $class )
$class string

The name of the class in which the exception was created.

                protected function setClass($class)
{
    $this->_class = $class;
}

            
setCode() protected method

protected void setCode ( $code )
$code mixed|integer

The exception code as integer.

                protected function setCode($code)
{
    $this->code = $code;
}

            
setFile() protected method

protected void setFile ( $file )
$file string

The filename in which the exception was created.

                protected function setFile($file)
{
    $this->file = $file;
}

            
setLine() protected method

protected void setLine ( $line )
$line integer

The line number where the exception was created.

                protected function setLine($line)
{
    $this->line = $line;
}

            
setMessage() protected method

protected void setMessage ( $message )
$message string

The Exception message as a string.

                protected function setMessage($message)
{
    $this->message = $message;
}

            
setPrevious() protected method

protected void setPrevious ( yii\debug\FlattenException $previous )
$previous yii\debug\FlattenException

Previous Exception.

                protected function setPrevious(FlattenException $previous)
{
    $this->_previous = $previous;
}

            
setToString() protected method

protected void setToString ( $string )
$string string

The string representation of the thrown object.

                protected function setToString($string)
{
    $this->_toString = $string;
}

            
setTrace() protected method

protected void setTrace ( $trace )
$trace array

The Exception stack trace as an array.

                protected function setTrace($trace)
{
    $this->_trace = [];
    foreach ($trace as $entry) {
        $class = '';
        $namespace = '';
        if (isset($entry['class'])) {
            $parts = explode('\\', $entry['class']);
            $class = array_pop($parts);
            $namespace = implode('\\', $parts);
        }
        $this->_trace[] = [
            'namespace' => $namespace,
            'short_class' => $class,
            'class' => isset($entry['class']) ? $entry['class'] : '',
            'type' => isset($entry['type']) ? $entry['type'] : '',
            'function' => isset($entry['function']) ? $entry['function'] : null,
            'file' => isset($entry['file']) ? $entry['file'] : null,
            'line' => isset($entry['line']) ? $entry['line'] : null,
            'args' => isset($entry['args']) ? $this->flattenArgs($entry['args']) : [],
        ];
    }
}