Skip to content

Commit

Permalink
update readme and toString method
Browse files Browse the repository at this point in the history
  • Loading branch information
Ping Cheng committed Apr 2, 2018
1 parent 3f5d1c3 commit 3b5a897
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ composer require pingcheng/api-response
| XML ||

# Usage


## Basic
```php
use PingCheng\ApiResponse\ApiResponse;
Expand All @@ -28,8 +29,7 @@ echo ApiResponse::json()
->data([
'id' => '1234',
'result' => 'accepted'
])
->output();
]);
```
The reuslt you would have
```json
Expand Down Expand Up @@ -58,8 +58,7 @@ echo ApiResponse::xml()
->data([
'id' => '1234',
'result' => 'accepted'
])
->output();
]);
```

the result you would have
Expand All @@ -75,12 +74,9 @@ the result you would have
</root>
```

If you need to remove a property added before, simple use
```php
...
->removeProperty('name')
...
```
## Property
- addProperty(name, value);
- removeProperty(name);

Basically, ApiReponse would auto add a status description to the result based on the status code, for example, if you add 200 code to the response, the api would automatically add a status of "OK!". If you need to modify it, please use this function to add it or remove it
```php
Expand All @@ -94,3 +90,8 @@ Basically, ApiReponse would auto add a status description to the result based on
->removeProperty('status')
...
```

## Headers control
- addHeader(name, value);
- removeHeader(name);
- removeAllHeaders();
11 changes: 11 additions & 0 deletions src/Packet/PacketBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,15 @@ protected function applyOptions($options) {
$this->send_code = isset($options['send_code']) ? $options['send_code'] : $this->send_code;
$this->headers = isset($options['headers']) ? $options['headers'] : $this->headers;
}

/**
* Magic method
* to parse this object to a text response
* automatically call the output method
* @return mixed
*/
public function __toString()
{
return $this->output();
}
}

0 comments on commit 3b5a897

Please sign in to comment.