class FindPostsResponse in HTTP Client Manager 8
Class FindPostsResponse.
@package Drupal\http_client_manager_example\Response
Hierarchy
- class \Drupal\http_client_manager_example\Response\FindPostsResponse implements \Guzzle\Service\Command\ResponseClassInterface
Expanded class hierarchy of FindPostsResponse
1 file declares its use of FindPostsResponse
- ExampleController.php in modules/
http_client_manager_example/ src/ Controller/ ExampleController.php
File
- modules/
http_client_manager_example/ src/ Response/ FindPostsResponse.php, line 13
Namespace
Drupal\http_client_manager_example\ResponseView source
class FindPostsResponse implements ResponseClassInterface {
/**
* The post author id.
*
* @var int
*/
protected $userId;
/**
* The post id.
*
* @var int
*/
protected $id;
/**
* The post title
*
* @var string
*/
protected $title;
/**
* The post body
*
* @var string
*/
protected $body;
/**
* {@inheritdoc}
*/
public static function fromCommand(OperationCommand $command) {
$results = $command
->getResponse()
->json();
if ($command
->get('postId')) {
return new self($results);
}
$posts = [];
foreach ($results as $result) {
$post = new self($result);
$posts[$post
->getId()] = $post;
}
return $posts;
}
/**
* FindPostsResponse constructor.
*
* @param array $json
* The JSON response.
*/
public function __construct($json) {
$this->userId = $json['userId'];
$this->id = $json['id'];
$this->title = $json['title'];
$this->body = $json['body'];
}
/**
* Get user id.
*
* @return int
* The post author id.
*/
public function getUserId() {
return $this->userId;
}
/**
* Set user id.
*
* @param int $userId
* The post author id.
*/
public function setUserId($userId) {
$this->userId = $userId;
}
/**
* Get id.
*
* @return int
* The post id.
*/
public function getId() {
return $this->id;
}
/**
* Set id.
*
* @param int $id
* The post id.
*/
public function setId($id) {
$this->id = $id;
}
/**
* Get title.
*
* @return string
* The post title.
*/
public function getTitle() {
return $this->title;
}
/**
* Set title.
*
* @param string $title
* The post title.
*/
public function setTitle($title) {
$this->title = $title;
}
/**
* Get body.
*
* @return string
* The post body.
*/
public function getBody() {
return $this->body;
}
/**
* Set body.
*
* @param string $body
* The post body.
*/
public function setBody($body) {
$this->body = $body;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FindPostsResponse:: |
protected | property | The post body | |
FindPostsResponse:: |
protected | property | The post id. | |
FindPostsResponse:: |
protected | property | The post title | |
FindPostsResponse:: |
protected | property | The post author id. | |
FindPostsResponse:: |
public static | function | ||
FindPostsResponse:: |
public | function | Get body. | |
FindPostsResponse:: |
public | function | Get id. | |
FindPostsResponse:: |
public | function | Get title. | |
FindPostsResponse:: |
public | function | Get user id. | |
FindPostsResponse:: |
public | function | Set body. | |
FindPostsResponse:: |
public | function | Set id. | |
FindPostsResponse:: |
public | function | Set title. | |
FindPostsResponse:: |
public | function | Set user id. | |
FindPostsResponse:: |
public | function | FindPostsResponse constructor. |