ActionResolverTrait.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace AlibabaCloud\Client\Resolver;
  3. use ReflectionClass;
  4. use ReflectionException;
  5. use AlibabaCloud\Client\AlibabaCloud;
  6. use AlibabaCloud\Client\Request\Request;
  7. use AlibabaCloud\Client\Exception\ClientException;
  8. /**
  9. * @codeCoverageIgnore
  10. * @mixin Rpc
  11. * @mixin Roa
  12. * @mixin Request
  13. * @package AlibabaCloud\Client\Resolver
  14. */
  15. trait ActionResolverTrait
  16. {
  17. /**
  18. * Resolve Action name from class name
  19. */
  20. private function resolveActionName()
  21. {
  22. if (!$this->action) {
  23. $array = explode('\\', get_class($this));
  24. $this->action = array_pop($array);
  25. }
  26. }
  27. /**
  28. * Append SDK version into User-Agent
  29. *
  30. * @throws ClientException
  31. * @throws ReflectionException
  32. */
  33. private function appendSdkUA()
  34. {
  35. if (!(new ReflectionClass(AlibabaCloud::class))->hasMethod('appendUserAgent')) {
  36. return;
  37. }
  38. if (!class_exists('AlibabaCloud\Release')) {
  39. return;
  40. }
  41. AlibabaCloud::appendUserAgent('SDK', \AlibabaCloud\Release::VERSION);
  42. }
  43. }