|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
*/ |
|
4
|
|
|
|
|
5
|
|
|
namespace Commercetools\Core\Model\Extension; |
|
6
|
|
|
|
|
7
|
|
|
use Commercetools\Core\Model\Common\JsonObject; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @package Commercetools\Core\Model\Extension |
|
11
|
|
|
* |
|
12
|
|
|
* @method string getType() |
|
13
|
|
|
* @method HttpDestinationAuthentication setType(string $type = null) |
|
14
|
|
|
*/ |
|
15
|
|
|
class HttpDestinationAuthentication extends JsonObject |
|
16
|
|
|
{ |
|
17
|
|
|
const AUTH_TYPE = null; |
|
18
|
|
|
const AUTH_AUTHORIZATION_HEADER = 'AuthorizationHeader'; |
|
19
|
|
|
const AUTH_AZURE_FUNCTIONS = 'AzureFunctions'; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @inheritDoc |
|
23
|
|
|
*/ |
|
24
|
6 |
|
public function __construct(array $data = [], $context = null) |
|
25
|
|
|
{ |
|
26
|
6 |
|
if (!is_null(static::AUTH_TYPE)) { |
|
|
|
|
|
|
27
|
4 |
|
$data[static::TYPE] = static::AUTH_TYPE; |
|
28
|
|
|
} |
|
29
|
6 |
|
parent::__construct($data, $context); |
|
30
|
6 |
|
} |
|
31
|
|
|
|
|
32
|
2 |
|
public function fieldDefinitions() |
|
33
|
|
|
{ |
|
34
|
|
|
return [ |
|
35
|
2 |
|
'type' => [static::TYPE => 'string'], |
|
36
|
|
|
]; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
protected static function authType($typeId) |
|
40
|
|
|
{ |
|
41
|
|
|
$types = [ |
|
42
|
|
|
static::AUTH_AUTHORIZATION_HEADER => AuthorizationHeaderAuthentication::class, |
|
43
|
|
|
static::AUTH_AZURE_FUNCTIONS => AzureFunctionsAuthentication::class, |
|
44
|
|
|
]; |
|
45
|
|
|
return isset($types[$typeId]) ? $types[$typeId] : Destination::class; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public static function fromArray(array $data, $context = null) |
|
49
|
|
|
{ |
|
50
|
|
|
if (get_called_class() == HttpDestinationAuthentication::class && isset($data[static::TYPE])) { |
|
51
|
|
|
$className = static::authType($data[static::TYPE]); |
|
52
|
|
|
if (class_exists($className)) { |
|
53
|
|
|
return new $className($data, $context); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
return new static($data, $context); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|