From 172f40aadaf1de54f7c05d98dfc57a5664a617a7 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Fri, 14 Jun 2013 17:06:01 -0400 Subject: [PATCH 1/5] Removed headers in ErrorHandler. --- framework/yii/base/ErrorHandler.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/framework/yii/base/ErrorHandler.php b/framework/yii/base/ErrorHandler.php index 1e6671b..338a392 100644 --- a/framework/yii/base/ErrorHandler.php +++ b/framework/yii/base/ErrorHandler.php @@ -90,6 +90,8 @@ class ErrorHandler extends Component $useErrorView = !YII_DEBUG || $exception instanceof UserException; $response = Yii::$app->getResponse(); + $response->getHeaders()->removeAll(); + if ($useErrorView && $this->errorAction !== null) { $result = Yii::$app->runAction($this->errorAction); if ($result instanceof Response) { From df0779fb142b829061313bc03ee54434d5277cb0 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Fri, 14 Jun 2013 17:10:36 -0400 Subject: [PATCH 2/5] Added previous exception in toArray(). --- framework/yii/base/Exception.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/framework/yii/base/Exception.php b/framework/yii/base/Exception.php index fe497a7..19317ca 100644 --- a/framework/yii/base/Exception.php +++ b/framework/yii/base/Exception.php @@ -29,11 +29,24 @@ class Exception extends \Exception implements Arrayable */ public function toArray() { - return array( + $array = array( 'type' => get_class($this), 'name' => $this->getName(), 'message' => $this->getMessage(), 'code' => $this->getCode(), ); + if (($prev = $this->getPrevious()) !== null) { + if ($prev instanceof self) { + $array['previous'] = $prev->toArray(); + } else { + $array['previous'] = array( + 'type' => get_class($prev), + 'name' => 'Exception', + 'message' => $prev->getMessage(), + 'code' => $prev->getCode(), + ); + } + } + return $array; } } From b184a75d6871a03e12faeb17a5dc44152fe4b18b Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Fri, 14 Jun 2013 17:15:28 -0400 Subject: [PATCH 3/5] Recursively return previous exceptions in toArray(). --- framework/yii/base/Exception.php | 44 ++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/framework/yii/base/Exception.php b/framework/yii/base/Exception.php index 19317ca..4f66e53 100644 --- a/framework/yii/base/Exception.php +++ b/framework/yii/base/Exception.php @@ -29,23 +29,33 @@ class Exception extends \Exception implements Arrayable */ public function toArray() { - $array = array( - 'type' => get_class($this), - 'name' => $this->getName(), - 'message' => $this->getMessage(), - 'code' => $this->getCode(), - ); - if (($prev = $this->getPrevious()) !== null) { - if ($prev instanceof self) { - $array['previous'] = $prev->toArray(); - } else { - $array['previous'] = array( - 'type' => get_class($prev), - 'name' => 'Exception', - 'message' => $prev->getMessage(), - 'code' => $prev->getCode(), - ); - } + return $this->toArrayRecursive($this); + } + + /** + * 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; } From d4910ee4f556a23aadbe732d3ba9e6c02aa613c1 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Fri, 14 Jun 2013 17:23:37 -0400 Subject: [PATCH 4/5] Put back Yii::getObjectVars() and fixed infinite loop in Object::toArray(). --- framework/yii/YiiBase.php | 13 +++++++++++++ framework/yii/base/Object.php | 4 +--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/framework/yii/YiiBase.php b/framework/yii/YiiBase.php index 4f85cae..35dc134 100644 --- a/framework/yii/YiiBase.php +++ b/framework/yii/YiiBase.php @@ -624,6 +624,19 @@ class YiiBase $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( diff --git a/framework/yii/base/Object.php b/framework/yii/base/Object.php index b7ab710..7724008 100644 --- a/framework/yii/base/Object.php +++ b/framework/yii/base/Object.php @@ -8,7 +8,6 @@ namespace yii\base; use Yii; -use yii\helpers\ArrayHelper; /** * @include @yii/base/Object.md @@ -223,11 +222,10 @@ class Object implements Arrayable /** * Converts the object into 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 */ public function toArray() { - return ArrayHelper::toArray($this, false); + return Yii::getObjectVars($this); } } From e0789ecb827ad64f729b4506c43ad23866a666ea Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Fri, 14 Jun 2013 17:23:57 -0400 Subject: [PATCH 5/5] Removed unused namespace. --- framework/yii/YiiBase.php | 1 - 1 file changed, 1 deletion(-) diff --git a/framework/yii/YiiBase.php b/framework/yii/YiiBase.php index 35dc134..ee75822 100644 --- a/framework/yii/YiiBase.php +++ b/framework/yii/YiiBase.php @@ -6,7 +6,6 @@ */ namespace yii; -use yii\base\Arrayable; use yii\base\Exception; use yii\base\InvalidConfigException; use yii\base\InvalidParamException;