Skip to content

Commit

Permalink
增加Response属性转数组方法
Browse files Browse the repository at this point in the history
  • Loading branch information
84hero committed Nov 21, 2017
1 parent ed8d735 commit 7643b96
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
2 changes: 2 additions & 0 deletions AliyunMNS/Responses/BaseResponse.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php
namespace AliyunMNS\Responses;
use AliyunMNS\Exception\MnsException;
use AliyunMNS\Traits\AttributesToArray;

abstract class BaseResponse
{
protected $succeed;
protected $statusCode;
use AttributesToArray;

abstract public function parseResponse($statusCode, $content);

Expand Down
19 changes: 19 additions & 0 deletions AliyunMNS/Traits/AttributesToArray.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
namespace AliyunMNS\Traits;

trait AttributesToArray
{
public function attributesToArray($object){
$attributes = [];
$refClass = new \ReflectionClass($object);
foreach ($refClass->getProperties() as $Properties){
$propertieName = $Properties->getName();
$method = 'get' . $propertieName;
$attributes[$propertieName] = $object->$method();
}
return $attributes;
}
}

?>

7 changes: 0 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,9 @@
"require": {
"php": ">=5.3.0",
"guzzlehttp/guzzle": "^6.3",
"ext-curl": "*",
"ext-openssl": "*",
"ext-dom": "*",
"ext-simplexml": "*"
},
"require-dev": {
"phpunit/phpunit": "^4.8"
},
"suggest": {

},
"autoload": {
"psr-4": {
Expand Down

0 comments on commit 7643b96

Please sign in to comment.