You are here

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\Response
View 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

Namesort descending Modifiers Type Description Overrides
FindPostsResponse::$body protected property The post body
FindPostsResponse::$id protected property The post id.
FindPostsResponse::$title protected property The post title
FindPostsResponse::$userId protected property The post author id.
FindPostsResponse::fromCommand public static function
FindPostsResponse::getBody public function Get body.
FindPostsResponse::getId public function Get id.
FindPostsResponse::getTitle public function Get title.
FindPostsResponse::getUserId public function Get user id.
FindPostsResponse::setBody public function Set body.
FindPostsResponse::setId public function Set id.
FindPostsResponse::setTitle public function Set title.
FindPostsResponse::setUserId public function Set user id.
FindPostsResponse::__construct public function FindPostsResponse constructor.