1 | <?php |
||
20 | class ConnectorFactory implements LoggerAwareInterface |
||
21 | { |
||
22 | use LoggerAwareTrait; |
||
23 | |||
24 | const PLATFORM_PATH = 'WebservicesNl\\Platform\\%1$s\\PlatformConfig'; |
||
25 | const PROTOCOL_PATH = 'WebservicesNl\\Protocol\\%1$s\\Client\\%1$sFactory'; |
||
26 | const ADAPTER_PATH = 'WebservicesNl\\Connector\\ProtocolAdapter\\%1$sAdapter'; |
||
27 | |||
28 | /** |
||
29 | * Generic user settings (eg credentials). |
||
30 | * |
||
31 | * @var array |
||
32 | */ |
||
33 | protected $userSettings; |
||
34 | |||
35 | /** |
||
36 | * ConnectorFactory constructor. |
||
37 | * |
||
38 | * @param array $settings |
||
39 | * @param LoggerInterface $logger |
||
|
|||
40 | */ |
||
41 | 6 | public function __construct(array $settings = [], LoggerInterface $logger = null) |
|
42 | { |
||
43 | 6 | $this->userSettings = $settings; |
|
44 | 6 | if ($logger instanceof LoggerInterface) { |
|
45 | 1 | $this->setLogger($logger); |
|
46 | 1 | } |
|
47 | 6 | } |
|
48 | |||
49 | /** |
||
50 | * @param array $settings |
||
51 | * @param LoggerInterface $logger |
||
52 | * |
||
53 | * @return static |
||
54 | */ |
||
55 | 6 | public static function build(array $settings = [], LoggerInterface $logger = null) |
|
59 | |||
60 | /** |
||
61 | * Creates an adapter for given platform and client. |
||
62 | * Wrap the client inside a platform adapter. |
||
63 | * |
||
64 | * @param ClientInterface $client |
||
65 | * |
||
66 | * @return AdapterInterface |
||
67 | * @throws InputException |
||
68 | */ |
||
69 | 3 | private function buildAdapter(ClientInterface $client) |
|
77 | |||
78 | /** |
||
79 | * Creates an connection for a given platform. |
||
80 | * |
||
81 | * @param string $protocolName type of connection (SOAP, REST etc) |
||
82 | * @param string $platformName name of platform (webservices) |
||
83 | * |
||
84 | * @return ConnectorInterface |
||
85 | * @throws InputException |
||
86 | */ |
||
87 | 6 | public function create($protocolName, $platformName) |
|
88 | { |
||
89 | 6 | $config = $this->createPlatformConfig($platformName); |
|
90 | |||
91 | // instantiate client factory for given protocol and pass along platform config. |
||
92 | 4 | $factory = $this->createProtocolFactory($protocolName, $config); |
|
93 | 3 | if ($this->getLogger() instanceof LoggerInterface) { |
|
94 | 2 | $factory->setLogger($this->getLogger()); |
|
95 | 2 | } |
|
96 | |||
97 | // build a protocol client (eg: Soap client, RPC client) |
||
98 | 3 | $client = $factory->create($this->userSettings); |
|
99 | |||
100 | // add the client to the wrapper (eg platform connector) |
||
101 | 3 | return $this->buildConnector($client, $config); |
|
102 | } |
||
103 | |||
104 | /** |
||
105 | * Build the connector with given client and platform config. |
||
106 | * |
||
107 | * @param ClientInterface $client |
||
108 | * @param PlatformConfigInterface $config |
||
109 | * |
||
110 | * @return ConnectorInterface |
||
111 | * @throws \WebservicesNl\Common\Exception\Client\InputException |
||
112 | */ |
||
113 | 3 | private function buildConnector(ClientInterface $client, PlatformConfigInterface $config) |
|
120 | |||
121 | /** |
||
122 | * @return LoggerInterface |
||
123 | */ |
||
124 | 3 | public function getLogger() |
|
128 | |||
129 | /** |
||
130 | * Tries to find the factory for given protocol, to configure and create the ClientInterface. |
||
131 | * |
||
132 | * @param string $protocolName name of the protocol |
||
133 | * @param PlatformConfigInterface $config platform config object |
||
134 | * |
||
135 | * @return ClientFactoryInterface |
||
136 | * @throws InputException |
||
137 | */ |
||
138 | 4 | private function createProtocolFactory($protocolName, PlatformConfigInterface $config) |
|
148 | |||
149 | /** |
||
150 | * Build a platform config with given settings. |
||
151 | * |
||
152 | * @param string $platformName |
||
153 | * |
||
154 | * @return PlatformConfigInterface |
||
155 | * @throws InputException |
||
156 | */ |
||
157 | 6 | private function createPlatformConfig($platformName) |
|
171 | } |
||
172 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.