| 1: | <?php |
| 2: | namespace Worldline\Connect\Sdk; |
| 3: | |
| 4: | use UnexpectedValueException; |
| 5: | use Worldline\Connect\Sdk\Domain\ShoppingCartExtension; |
| 6: | |
| 7: | /** |
| 8: | * Class CommunicatorConfiguration |
| 9: | * |
| 10: | * @package Worldline\Connect\Sdk |
| 11: | */ |
| 12: | class CommunicatorConfiguration |
| 13: | { |
| 14: | /** |
| 15: | * @var string |
| 16: | */ |
| 17: | private $authorizationId; |
| 18: | |
| 19: | /** |
| 20: | * @var string |
| 21: | */ |
| 22: | private $authorizationSecret; |
| 23: | |
| 24: | /** |
| 25: | * @var string |
| 26: | */ |
| 27: | private $apiEndpoint; |
| 28: | |
| 29: | /** @var int */ |
| 30: | private $connectTimeout; |
| 31: | |
| 32: | /** @var int */ |
| 33: | private $readTimeout; |
| 34: | |
| 35: | /** |
| 36: | * @var ProxyConfiguration|null |
| 37: | */ |
| 38: | private $proxyConfiguration; |
| 39: | |
| 40: | /** |
| 41: | * @var string |
| 42: | */ |
| 43: | private $integrator; |
| 44: | |
| 45: | /** |
| 46: | * @var ShoppingCartExtension|null |
| 47: | */ |
| 48: | private $shoppingCartExtension = null; |
| 49: | |
| 50: | /** |
| 51: | * @param string $authorizationId |
| 52: | * @param string $authorizationSecret |
| 53: | * @param string $apiEndpoint |
| 54: | * @param string $integrator |
| 55: | * @param ProxyConfiguration|null $proxyConfiguration |
| 56: | * @param int $connectTimeout |
| 57: | * @param int $readTimeout |
| 58: | */ |
| 59: | public function __construct( |
| 60: | $authorizationId, |
| 61: | $authorizationSecret, |
| 62: | $apiEndpoint, |
| 63: | $integrator, |
| 64: | ProxyConfiguration $proxyConfiguration = null, |
| 65: | $connectTimeout = -1, |
| 66: | $readTimeout = -1) |
| 67: | { |
| 68: | $this->validateApiEndpoint($apiEndpoint); |
| 69: | $this->validateIntegrator($integrator); |
| 70: | $this->authorizationId = $authorizationId; |
| 71: | $this->authorizationSecret = $authorizationSecret; |
| 72: | $this->apiEndpoint = $apiEndpoint; |
| 73: | $this->integrator = $integrator; |
| 74: | $this->proxyConfiguration = $proxyConfiguration; |
| 75: | $this->connectTimeout = $connectTimeout; |
| 76: | $this->readTimeout = $readTimeout; |
| 77: | } |
| 78: | |
| 79: | private function validateApiEndpoint($apiEndpoint) |
| 80: | { |
| 81: | $url = parse_url($apiEndpoint); |
| 82: | if ($url === false) { |
| 83: | throw new UnexpectedValueException('apiEndpoint is not a valid URL'); |
| 84: | } elseif (isset($url['path']) && $url['path'] !== '') { |
| 85: | throw new UnexpectedValueException('apiEndpoint should not contain a path'); |
| 86: | } elseif (isset($url['user']) || isset($url['query']) || isset($url['fragment'])) { |
| 87: | throw new UnexpectedValueException('apiEndpoint should not contain user info, query or fragment'); |
| 88: | } |
| 89: | } |
| 90: | |
| 91: | private function validateIntegrator($integrator) |
| 92: | { |
| 93: | if (is_null($integrator) || strlen(trim($integrator)) == 0) { |
| 94: | throw new UnexpectedValueException("integrator is required"); |
| 95: | } |
| 96: | } |
| 97: | |
| 98: | /** |
| 99: | * @return string An id used for authorization. This can be the identifier for a secret API key, or something else. |
| 100: | */ |
| 101: | public function getAuthorizationId() |
| 102: | { |
| 103: | return $this->authorizationId; |
| 104: | } |
| 105: | |
| 106: | /** |
| 107: | * @param string $authorizationId |
| 108: | */ |
| 109: | public function setAuthorizationId($authorizationId) |
| 110: | { |
| 111: | $this->authorizationId = $authorizationId; |
| 112: | } |
| 113: | |
| 114: | /** |
| 115: | * @return string A secret used for authorization. This can be a secret API key, or something else. |
| 116: | */ |
| 117: | public function getAuthorizationSecret() |
| 118: | { |
| 119: | return $this->authorizationSecret; |
| 120: | } |
| 121: | |
| 122: | /** |
| 123: | * @param string $authorizationSecret |
| 124: | */ |
| 125: | public function setAuthorizationSecret($authorizationSecret) |
| 126: | { |
| 127: | $this->authorizationSecret = $authorizationSecret; |
| 128: | } |
| 129: | |
| 130: | /** |
| 131: | * This method is an alias for getAuthorizationId. |
| 132: | * @return string |
| 133: | */ |
| 134: | public function getApiKeyId() |
| 135: | { |
| 136: | return $this->getAuthorizationId(); |
| 137: | } |
| 138: | |
| 139: | /** |
| 140: | * This method is an alias for setAuthorizationId. |
| 141: | * @param string $apiKeyId |
| 142: | */ |
| 143: | public function setApiKeyId($apiKeyId) |
| 144: | { |
| 145: | $this->setAuthorizationId($apiKeyId); |
| 146: | } |
| 147: | |
| 148: | /** |
| 149: | * This method is an alias for getAuthorizationSecret. |
| 150: | * @return string |
| 151: | */ |
| 152: | public function getApiSecret() |
| 153: | { |
| 154: | return $this->getAuthorizationSecret(); |
| 155: | } |
| 156: | |
| 157: | /** |
| 158: | * This method is an alias for setAuthorizationSecret. |
| 159: | * @param string $apiSecret |
| 160: | */ |
| 161: | public function setApiSecret($apiSecret) |
| 162: | { |
| 163: | $this->setAuthorizationSecret($apiSecret); |
| 164: | } |
| 165: | |
| 166: | /** |
| 167: | * @return string |
| 168: | */ |
| 169: | public function getApiEndpoint() |
| 170: | { |
| 171: | return $this->apiEndpoint; |
| 172: | } |
| 173: | |
| 174: | /** |
| 175: | * @param string $apiEndpoint |
| 176: | */ |
| 177: | public function setApiEndpoint($apiEndpoint) |
| 178: | { |
| 179: | $this->validateApiEndpoint($apiEndpoint); |
| 180: | $this->apiEndpoint = $apiEndpoint; |
| 181: | } |
| 182: | |
| 183: | /** |
| 184: | * @return ProxyConfiguration|null |
| 185: | */ |
| 186: | public function getProxyConfiguration() |
| 187: | { |
| 188: | return $this->proxyConfiguration; |
| 189: | } |
| 190: | |
| 191: | /** |
| 192: | * @param ProxyConfiguration|null $proxyConfiguration |
| 193: | */ |
| 194: | public function setProxyConfiguration(ProxyConfiguration $proxyConfiguration = null) |
| 195: | { |
| 196: | $this->proxyConfiguration = $proxyConfiguration; |
| 197: | } |
| 198: | |
| 199: | /** |
| 200: | * @return int |
| 201: | */ |
| 202: | public function getConnectTimeout() |
| 203: | { |
| 204: | return $this->connectTimeout; |
| 205: | } |
| 206: | |
| 207: | /** |
| 208: | * @param int $connectTimeout |
| 209: | */ |
| 210: | public function setConnectTimeout($connectTimeout) |
| 211: | { |
| 212: | $this->connectTimeout = $connectTimeout; |
| 213: | } |
| 214: | |
| 215: | /** |
| 216: | * @return int |
| 217: | */ |
| 218: | public function getReadTimeout() |
| 219: | { |
| 220: | return $this->readTimeout; |
| 221: | } |
| 222: | |
| 223: | /** |
| 224: | * @param int $readTimeout |
| 225: | */ |
| 226: | public function setReadTimeout($readTimeout) |
| 227: | { |
| 228: | $this->readTimeout = $readTimeout; |
| 229: | } |
| 230: | |
| 231: | /** |
| 232: | * @return string |
| 233: | */ |
| 234: | public function getIntegrator() |
| 235: | { |
| 236: | return $this->integrator; |
| 237: | } |
| 238: | |
| 239: | /** |
| 240: | * @param string $integrator |
| 241: | */ |
| 242: | public function setIntegrator($integrator) |
| 243: | { |
| 244: | $this->validateIntegrator($integrator); |
| 245: | $this->integrator = $integrator; |
| 246: | } |
| 247: | |
| 248: | /** |
| 249: | * @return ShoppingCartExtension|null |
| 250: | */ |
| 251: | public function getShoppingCartExtension() |
| 252: | { |
| 253: | return $this->shoppingCartExtension; |
| 254: | } |
| 255: | |
| 256: | /** |
| 257: | * @param ShoppingCartExtension|null $shoppingCartExtension |
| 258: | */ |
| 259: | public function setShoppingCartExtension(ShoppingCartExtension $shoppingCartExtension = null) |
| 260: | { |
| 261: | $this->shoppingCartExtension = $shoppingCartExtension; |
| 262: | } |
| 263: | } |
| 264: |