mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-17 14:57:23 +08:00
Merge branch 'master' of github.com:yiisoft/yii2
* 'master' of github.com:yiisoft/yii2: Removed unused namespace. Put back Yii::getObjectVars() and fixed infinite loop in Object::toArray(). Recursively return previous exceptions in toArray(). Added previous exception in toArray(). Removed headers in ErrorHandler.
This commit is contained in:
@@ -6,7 +6,6 @@
|
|||||||
*/
|
*/
|
||||||
namespace yii;
|
namespace yii;
|
||||||
|
|
||||||
use yii\base\Arrayable;
|
|
||||||
use yii\base\Exception;
|
use yii\base\Exception;
|
||||||
use yii\base\InvalidConfigException;
|
use yii\base\InvalidConfigException;
|
||||||
use yii\base\InvalidParamException;
|
use yii\base\InvalidParamException;
|
||||||
@@ -624,6 +623,19 @@ class YiiBase
|
|||||||
$object->$name = $value;
|
$object->$name = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the public member variables of an object.
|
||||||
|
* This method is provided such that we can get the public member variables of an object.
|
||||||
|
* It is different from "get_object_vars()" because the latter will return private
|
||||||
|
* and protected variables if it is called within the object itself.
|
||||||
|
* @param object $object the object to be handled
|
||||||
|
* @return array the public member variables of the object
|
||||||
|
*/
|
||||||
|
public static function getObjectVars($object)
|
||||||
|
{
|
||||||
|
return get_object_vars($object);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
YiiBase::$aliases = array(
|
YiiBase::$aliases = array(
|
||||||
|
|||||||
@@ -90,6 +90,8 @@ class ErrorHandler extends Component
|
|||||||
$useErrorView = !YII_DEBUG || $exception instanceof UserException;
|
$useErrorView = !YII_DEBUG || $exception instanceof UserException;
|
||||||
|
|
||||||
$response = Yii::$app->getResponse();
|
$response = Yii::$app->getResponse();
|
||||||
|
$response->getHeaders()->removeAll();
|
||||||
|
|
||||||
if ($useErrorView && $this->errorAction !== null) {
|
if ($useErrorView && $this->errorAction !== null) {
|
||||||
$result = Yii::$app->runAction($this->errorAction);
|
$result = Yii::$app->runAction($this->errorAction);
|
||||||
if ($result instanceof Response) {
|
if ($result instanceof Response) {
|
||||||
|
|||||||
@@ -29,11 +29,34 @@ class Exception extends \Exception implements Arrayable
|
|||||||
*/
|
*/
|
||||||
public function toArray()
|
public function toArray()
|
||||||
{
|
{
|
||||||
return array(
|
return $this->toArrayRecursive($this);
|
||||||
'type' => get_class($this),
|
}
|
||||||
'name' => $this->getName(),
|
|
||||||
'message' => $this->getMessage(),
|
/**
|
||||||
'code' => $this->getCode(),
|
* Returns the array representation of the exception and all previous exceptions recursively.
|
||||||
);
|
* @param \Exception exception object
|
||||||
|
* @return array the array representation of the exception.
|
||||||
|
*/
|
||||||
|
protected function toArrayRecursive($exception)
|
||||||
|
{
|
||||||
|
if ($exception instanceof self) {
|
||||||
|
$array = array(
|
||||||
|
'type' => get_class($this),
|
||||||
|
'name' => $this->getName(),
|
||||||
|
'message' => $this->getMessage(),
|
||||||
|
'code' => $this->getCode(),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$array = array(
|
||||||
|
'type' => get_class($exception),
|
||||||
|
'name' => 'Exception',
|
||||||
|
'message' => $exception->getMessage(),
|
||||||
|
'code' => $exception->getCode(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (($prev = $exception->getPrevious()) !== null) {
|
||||||
|
$array['previous'] = $this->toArrayRecursive($prev);
|
||||||
|
}
|
||||||
|
return $array;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
namespace yii\base;
|
namespace yii\base;
|
||||||
|
|
||||||
use Yii;
|
use Yii;
|
||||||
use yii\helpers\ArrayHelper;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @include @yii/base/Object.md
|
* @include @yii/base/Object.md
|
||||||
@@ -223,11 +222,10 @@ class Object implements Arrayable
|
|||||||
/**
|
/**
|
||||||
* Converts the object into an array.
|
* Converts the object into an array.
|
||||||
* The default implementation will return all public property values as an array.
|
* The default implementation will return all public property values as an array.
|
||||||
* However, if the object is traversable, it will return the data obtained by the data iteration.
|
|
||||||
* @return array the array representation of the object
|
* @return array the array representation of the object
|
||||||
*/
|
*/
|
||||||
public function toArray()
|
public function toArray()
|
||||||
{
|
{
|
||||||
return ArrayHelper::toArray($this, false);
|
return Yii::getObjectVars($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user