Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Response;
- class ApiResponse
- {
- private $response = [];
- public function addProperty(string $name, string $value)
- :self
- {
- $this->response[$name] = $value;
- return $this;
- }
- public function fromJson(string $json)
- :self
- {
- //maybe allow to call this function when response is not touched, in other case throw exception?
- //or remove this and do it in constructor
- $this->response = json_decode($json);
- return $this;
- }
- public function fromArray(array $array)
- : self
- {
- //same comment apply as for fromJson function
- $this->response = $array;
- return $this;
- }
- public function toJson()
- :string
- {
- return json_encode($this->response);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement