Transport.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /**
  3. * @link http://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license http://www.yiiframework.com/license/
  6. */
  7. namespace yii\httpclient;
  8. use yii\base\Component;
  9. /**
  10. * Transport performs actual HTTP request sending.
  11. *
  12. * @author Paul Klimov <klimov.paul@gmail.com>
  13. * @since 2.0
  14. */
  15. abstract class Transport extends Component
  16. {
  17. /**
  18. * Performs given request.
  19. * @param Request $request request to be sent.
  20. * @return Response response instance.
  21. * @throws Exception on failure.
  22. */
  23. abstract public function send($request);
  24. /**
  25. * Performs multiple HTTP requests.
  26. * Particular transport may benefit from this method, allowing sending requests in parallel.
  27. * This method accepts an array of the [[Request]] objects and returns an array of the [[Response]] objects.
  28. * Keys of the response array correspond the ones from request array.
  29. * @param Request[] $requests requests to perform.
  30. * @return Response[] responses list.
  31. */
  32. public function batchSend(array $requests)
  33. {
  34. $responses = [];
  35. foreach ($requests as $key => $request) {
  36. $responses[$key] = $this->send($request);
  37. }
  38. return $responses;
  39. }
  40. }