ServiceClientInterface.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace GuzzleHttp\Command;
  3. use GuzzleHttp\ClientInterface;
  4. use GuzzleHttp\Command\Exception\CommandException;
  5. use GuzzleHttp\HandlerStack;
  6. use GuzzleHttp\Promise\PromiseInterface;
  7. /**
  8. * Web service client interface.
  9. */
  10. interface ServiceClientInterface
  11. {
  12. /**
  13. * Create a command for an operation name.
  14. *
  15. * Special keys may be set on the command to control how it behaves.
  16. * Implementations SHOULD be able to utilize the following keys or throw
  17. * an exception if unable.
  18. *
  19. * @param string $name Name of the operation to use in the command
  20. * @param array $args Arguments to pass to the command
  21. *
  22. * @return CommandInterface
  23. *
  24. * @throws \InvalidArgumentException if no command can be found by name
  25. */
  26. public function getCommand($name, array $args = []);
  27. /**
  28. * Execute a single command.
  29. *
  30. * @param CommandInterface $command Command to execute
  31. *
  32. * @return ResultInterface The result of the executed command
  33. *
  34. * @throws CommandException
  35. */
  36. public function execute(CommandInterface $command);
  37. /**
  38. * Execute a single command asynchronously
  39. *
  40. * @param CommandInterface $command Command to execute
  41. *
  42. * @return PromiseInterface A Promise that resolves to a Result.
  43. */
  44. public function executeAsync(CommandInterface $command);
  45. /**
  46. * Executes multiple commands concurrently using a fixed pool size.
  47. *
  48. * @param array|\Iterator $commands Array or iterator that contains
  49. * CommandInterface objects to execute with the client.
  50. * @param array $options Associative array of options to apply.
  51. * - concurrency: (int) Max number of commands to execute concurrently.
  52. * - fulfilled: (callable) Function to invoke when a command completes.
  53. * - rejected: (callable) Function to invoke when a command fails.
  54. *
  55. * @return array
  56. *
  57. * @see GuzzleHttp\Command\ServiceClientInterface::createPool for options.
  58. */
  59. public function executeAll($commands, array $options = []);
  60. /**
  61. * Executes multiple commands concurrently and asynchronously using a
  62. * fixed pool size.
  63. *
  64. * @param array|\Iterator $commands Array or iterator that contains
  65. * CommandInterface objects to execute with the client.
  66. * @param array $options Associative array of options to apply.
  67. * - concurrency: (int) Max number of commands to execute concurrently.
  68. * - fulfilled: (callable) Function to invoke when a command completes.
  69. * - rejected: (callable) Function to invoke when a command fails.
  70. *
  71. * @return PromiseInterface
  72. *
  73. * @see GuzzleHttp\Command\ServiceClientInterface::createPool for options.
  74. */
  75. public function executeAllAsync($commands, array $options = []);
  76. /**
  77. * Get the HTTP client used to send requests for the web service client
  78. *
  79. * @return ClientInterface
  80. */
  81. public function getHttpClient();
  82. /**
  83. * Get the HandlerStack which can be used to add middleware to the client.
  84. *
  85. * @return HandlerStack
  86. */
  87. public function getHandlerStack();
  88. }