Class yii\debug\FlattenException
Inheritance | yii\debug\FlattenException |
---|---|
Available since extension's version | 2.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
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 |
Protected Methods
Property Details
Method Details
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));
}
}
String representation of the exception
public string __toString ( ) | ||
return | string |
The string representation of the exception. |
---|
public function __toString()
{
return $this->_toString;
}
public string getClass ( ) | ||
return | string |
The name of the class in which the exception was created. |
---|
public function getClass()
{
return $this->_class;
}
Gets the Exception code
public mixed|integer getCode ( ) | ||
return | mixed|integer |
The exception code as integer. |
---|
public function getCode()
{
return $this->code;
}
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;
}
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;
}
Gets the Exception message
public string getMessage ( ) | ||
return | string |
The Exception message as a string. |
---|
public function getMessage()
{
return $this->message;
}
Returns previous Exception
public yii\debug\FlattenException getPrevious ( ) | ||
return | yii\debug\FlattenException |
The previous |
---|
public function getPrevious()
{
return $this->_previous;
}
Gets the stack trace
public array getTrace ( ) | ||
return | array |
The Exception stack trace as an array. |
---|
public function getTrace()
{
return $this->_trace;
}
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));
}
protected void setClass ( $class ) | ||
$class | string |
The name of the class in which the exception was created. |
protected function setClass($class)
{
$this->_class = $class;
}
protected void setCode ( $code ) | ||
$code | mixed|integer |
The exception code as integer. |
protected function setCode($code)
{
$this->code = $code;
}
protected void setFile ( $file ) | ||
$file | string |
The filename in which the exception was created. |
protected function setFile($file)
{
$this->file = $file;
}
protected void setLine ( $line ) | ||
$line | integer |
The line number where the exception was created. |
protected function setLine($line)
{
$this->line = $line;
}
protected void setMessage ( $message ) | ||
$message | string |
The Exception message as a string. |
protected function setMessage($message)
{
$this->message = $message;
}
protected void setPrevious ( yii\debug\FlattenException $previous ) | ||
$previous | yii\debug\FlattenException |
Previous Exception. |
protected function setPrevious(FlattenException $previous)
{
$this->_previous = $previous;
}
protected void setToString ( $string ) | ||
$string | string |
The string representation of the thrown object. |
protected function setToString($string)
{
$this->_toString = $string;
}
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']) : [],
];
}
}