You are here

public static function FindPostsResponse::fromCommand in HTTP Client Manager 8

File

modules/http_client_manager_example/src/Response/FindPostsResponse.php, line 46

Class

FindPostsResponse
Class FindPostsResponse.

Namespace

Drupal\http_client_manager_example\Response

Code

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;
}