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

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 __construct( Exception $exception ): mixed
$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 __toString( ): string
return string

The string representation of the exception.

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

            
getClass() public method

public getClass( ): string
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 getCode( ): mixed|integer
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 getFile( ): string
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 getLine( ): integer
return integer

The line number where the exception was created.

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

            
getMessage() public method

Gets the Exception message

public getMessage( ): string
return string

The Exception message as a string.

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

            
getPrevious() public method

Returns previous Exception

public getPrevious( ): yii\debug\FlattenException
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 getTrace( ): array
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 getTraceAsString( ): string
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 setClass( string $class ): mixed
$class string

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

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

            
setCode() protected method

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

The exception code as integer.

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

            
setFile() protected method

protected setFile( string $file ): mixed
$file string

The filename in which the exception was created.

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

            
setLine() protected method

protected setLine( integer $line ): mixed
$line integer

The line number where the exception was created.

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

            
setMessage() protected method

protected setMessage( string $message ): mixed
$message string

The Exception message as a string.

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

            
setPrevious() protected method

protected setPrevious( yii\debug\FlattenException $previous ): mixed
$previous yii\debug\FlattenException

Previous Exception.

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

            
setToString() protected method

protected setToString( string $string ): mixed
$string string

The string representation of the thrown object.

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

            
setTrace() protected method

protected setTrace( array $trace ): mixed
$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']) : [],
        ];
    }
}