FindPostsResponse.php in HTTP Client Manager 8
File
modules/http_client_manager_example/src/Response/FindPostsResponse.phpView source
<?php
namespace Drupal\http_client_manager_example\Response;
use Guzzle\Service\Command\OperationCommand;
use Guzzle\Service\Command\ResponseClassInterface;
/**
* Class FindPostsResponse.
*
* @package Drupal\http_client_manager_example\Response
*/
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;
}
}
Classes
Name | Description |
---|---|
FindPostsResponse | Class FindPostsResponse. |