1: <?php
2: namespace Worldline\Connect\Sdk\Communication;
3:
4: use stdClass;
5: use Worldline\Connect\Sdk\CommunicatorConfiguration;
6: use Worldline\Connect\Sdk\Domain\ShoppingCartExtension;
7:
8: /**
9: * Class MetadataProvider
10: *
11: * @package Worldline\Connect\Sdk\Communication
12: */
13: class MetadataProvider
14: {
15: const SDK_VERSION = '7.2.0';
16:
17: /** @var string */
18: private $integrator;
19:
20: /** @var ShoppingCartExtension */
21: private $shoppingCartExtension;
22:
23: /**
24: * @param CommunicatorConfiguration $communicatorConfiguration
25: */
26: public function __construct(CommunicatorConfiguration $communicatorConfiguration) {
27: $this->integrator = $communicatorConfiguration->getIntegrator();
28: $this->shoppingCartExtension = $communicatorConfiguration->getShoppingCartExtension();
29: }
30:
31: /**
32: * @return string
33: */
34: public function getServerMetaInfoValue()
35: {
36: // use a stdClass instead of specific class to keep out null properties
37: $serverMetaInfo = new stdClass();
38: $serverMetaInfo->platformIdentifier = sprintf('%s; php version %s', php_uname(), phpversion());
39: $serverMetaInfo->sdkIdentifier = 'PHPServerSDK/v' . static::SDK_VERSION;
40: $serverMetaInfo->sdkCreator = 'Worldline';
41: $serverMetaInfo->integrator = $this->integrator;
42: if (!is_null($this->shoppingCartExtension)) {
43: $serverMetaInfo->shoppingCartExtension = $this->shoppingCartExtension->toObject();
44: }
45: // the sdkIdentifier contains a /. Without the JSON_UNESCAPED_SLASHES, this is turned to \/ in JSON.
46: return base64_encode(json_encode($serverMetaInfo, JSON_UNESCAPED_SLASHES));
47: }
48: }
49: