RequestHeaders.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
  4. */
  5. namespace Temando\Shipping\Rest\Request;
  6. use Temando\Shipping\Rest\AuthenticationInterface;
  7. use Temando\Shipping\Webservice\Config\WsConfigInterface;
  8. /**
  9. * Temando API Request Headers
  10. *
  11. * @package Temando\Shipping\Rest
  12. * @author Christoph Aßmann <christoph.assmann@netresearch.de>
  13. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  14. * @link http://www.temando.com/
  15. */
  16. class RequestHeaders implements RequestHeadersInterface
  17. {
  18. /**
  19. * @var string
  20. */
  21. private $endpoint;
  22. /**
  23. * @var string
  24. */
  25. private $apiVersion;
  26. /**
  27. * @var AuthenticationInterface
  28. */
  29. private $auth;
  30. /**
  31. * Adapter constructor.
  32. * @param WsConfigInterface $config
  33. * @param AuthenticationInterface $auth,
  34. */
  35. public function __construct(
  36. WsConfigInterface $config,
  37. AuthenticationInterface $auth
  38. ) {
  39. $this->endpoint = $config->getApiEndpoint();
  40. $this->apiVersion = $config->getApiVersion();
  41. $this->auth = $auth;
  42. }
  43. /**
  44. * @return string[]
  45. */
  46. public function getHeaders()
  47. {
  48. return [
  49. 'Cache-Control' => 'no-cache',
  50. 'Content-Type' => 'application/vnd.api+json',
  51. 'Accept' => 'application/vnd.api+json',
  52. 'Origin' => $this->endpoint,
  53. 'Version' => $this->apiVersion,
  54. 'Authorization' => sprintf('Bearer %s', $this->auth->getSessionToken()),
  55. ];
  56. }
  57. }