1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DMT\WebservicesNl\Client\Factory; |
4
|
|
|
|
5
|
|
|
use DMT\CommandBus\Validator\ValidationMiddleware; |
6
|
|
|
use DMT\WebservicesNl\Client\Client; |
7
|
|
|
use DMT\WebservicesNl\Client\Command\Handler\Locator\CommandHandlerResolver; |
8
|
|
|
use DMT\WebservicesNl\Client\Command\Handler\MethodNameInflector\ClassNameWithoutSuffixInflector; |
9
|
|
|
use DMT\WebservicesNl\Client\Command\Middleware\ExceptionMiddleware; |
10
|
|
|
use Doctrine\Common\Annotations\AnnotationException; |
11
|
|
|
use Doctrine\Common\Annotations\AnnotationRegistry; |
12
|
|
|
use JMS\Serializer\Naming\CamelCaseNamingStrategy; |
13
|
|
|
use JMS\Serializer\Naming\PropertyNamingStrategyInterface; |
14
|
|
|
use JMS\Serializer\Naming\SerializedNameAnnotationStrategy; |
15
|
|
|
use League\Tactician\CommandBus; |
16
|
|
|
use League\Tactician\Handler\CommandHandlerMiddleware; |
17
|
|
|
use League\Tactician\Handler\CommandNameExtractor\ClassNameExtractor; |
18
|
|
|
use League\Tactician\Handler\Locator\CallableLocator; |
19
|
|
|
use League\Tactician\Plugins\LockingMiddleware; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class AbstractClientBuilder |
23
|
|
|
* |
24
|
|
|
* @package DMT\WebservicesNl\Client |
25
|
|
|
*/ |
26
|
|
|
abstract class AbstractClientBuilder |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
protected $endpoint; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var PropertyNamingStrategyInterface |
35
|
|
|
*/ |
36
|
|
|
protected $namingStrategy; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var string |
40
|
|
|
*/ |
41
|
|
|
protected $serializerFormat; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* ClientBuilder constructor. |
45
|
|
|
* @param string|null $serializerFormat |
46
|
|
|
*/ |
47
|
10 |
|
final public function __construct(string $serializerFormat = null) |
48
|
|
|
{ |
49
|
10 |
|
AnnotationRegistry::registerUniqueLoader('class_exists'); |
|
|
|
|
50
|
|
|
|
51
|
10 |
|
$this->namingStrategy = new SerializedNameAnnotationStrategy(new CamelCaseNamingStrategy()); |
52
|
10 |
|
$this->serializerFormat = $serializerFormat; |
53
|
10 |
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param string|null $serializerFormat |
57
|
|
|
* @return AbstractClientBuilder |
58
|
|
|
*/ |
59
|
10 |
|
public static function create(string $serializerFormat = null): self |
60
|
|
|
{ |
61
|
10 |
|
return new static($serializerFormat); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Build the webservices client. |
66
|
|
|
* |
67
|
|
|
* @return Client |
68
|
|
|
* @throws AnnotationException |
69
|
|
|
*/ |
70
|
2 |
|
public function build(): Client |
71
|
|
|
{ |
72
|
2 |
|
return new Client( |
73
|
2 |
|
new CommandBus( |
74
|
|
|
[ |
75
|
2 |
|
new LockingMiddleware(), |
76
|
2 |
|
new ExceptionMiddleware(), |
77
|
2 |
|
new ValidationMiddleware(), |
78
|
2 |
|
new CommandHandlerMiddleware( |
79
|
2 |
|
new ClassNameExtractor(), |
80
|
2 |
|
new CallableLocator($this->getCommandResolver()), |
81
|
2 |
|
new ClassNameWithoutSuffixInflector('Request') |
82
|
|
|
) |
83
|
|
|
] |
84
|
|
|
) |
85
|
|
|
); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Set endpoint for SOAP service. |
90
|
|
|
* |
91
|
|
|
* @param string $endpoint |
92
|
|
|
* |
93
|
|
|
* @return AbstractClientBuilder |
94
|
|
|
*/ |
95
|
6 |
|
public function setServiceEndpoint(string $endpoint): AbstractClientBuilder |
96
|
|
|
{ |
97
|
6 |
|
if (!filter_var($endpoint, FILTER_VALIDATE_URL) || parse_url($endpoint, PHP_URL_SCHEME) !== 'https') { |
98
|
3 |
|
throw new \InvalidArgumentException('Incorrect endpoint given'); |
99
|
|
|
} |
100
|
|
|
|
101
|
3 |
|
$this->endpoint = $endpoint; |
102
|
|
|
|
103
|
3 |
|
return $this; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Set the authentication. |
108
|
|
|
* |
109
|
|
|
* @param array $credentials |
110
|
|
|
* |
111
|
|
|
* @return AbstractClientBuilder |
112
|
|
|
* @throws \InvalidArgumentException |
113
|
|
|
*/ |
114
|
|
|
abstract public function setAuthentication(array $credentials): AbstractClientBuilder; |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Get a configured command resolver for the requested endpoint. |
118
|
|
|
* |
119
|
|
|
* @return CommandHandlerResolver |
120
|
|
|
*/ |
121
|
|
|
abstract protected function getCommandResolver(): CommandHandlerResolver; |
122
|
|
|
} |
123
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.