RequestTrait.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace AlibabaCloud\Client\Traits;
  3. use AlibabaCloud\Client\AlibabaCloud;
  4. use AlibabaCloud\Client\Filter\Filter;
  5. use AlibabaCloud\Client\Request\UserAgent;
  6. use AlibabaCloud\Client\Request\RpcRequest;
  7. use AlibabaCloud\Client\Request\RoaRequest;
  8. use AlibabaCloud\Client\Exception\ClientException;
  9. /**
  10. * Trait RequestTrait
  11. *
  12. * @package AlibabaCloud\Client\Traits
  13. *
  14. * @mixin AlibabaCloud
  15. */
  16. trait RequestTrait
  17. {
  18. /**
  19. * @param string $name
  20. * @param string $value
  21. *
  22. * @throws ClientException
  23. */
  24. public static function appendUserAgent($name, $value)
  25. {
  26. Filter::name($name);
  27. Filter::value($value);
  28. UserAgent::append($name, $value);
  29. }
  30. /**
  31. * @param array $userAgent
  32. */
  33. public static function withUserAgent(array $userAgent)
  34. {
  35. UserAgent::with($userAgent);
  36. }
  37. /**
  38. * @param array $options
  39. *
  40. * @return RpcRequest
  41. * @throws ClientException
  42. * @deprecated
  43. * @codeCoverageIgnore
  44. */
  45. public static function rpcRequest(array $options = [])
  46. {
  47. return self::rpc($options);
  48. }
  49. /**
  50. * @param array $options
  51. *
  52. * @return RpcRequest
  53. * @throws ClientException
  54. */
  55. public static function rpc(array $options = [])
  56. {
  57. return new RpcRequest($options);
  58. }
  59. /**
  60. * @param array $options
  61. *
  62. * @return RoaRequest
  63. * @throws ClientException
  64. * @deprecated
  65. * @codeCoverageIgnore
  66. */
  67. public static function roaRequest(array $options = [])
  68. {
  69. return self::roa($options);
  70. }
  71. /**
  72. * @param array $options
  73. *
  74. * @return RoaRequest
  75. * @throws ClientException
  76. */
  77. public static function roa(array $options = [])
  78. {
  79. return new RoaRequest($options);
  80. }
  81. }