1 | <?php |
||
60 | class Base implements RequestCreatorInterface |
||
61 | { |
||
62 | /** |
||
63 | * Parameters |
||
64 | * |
||
65 | * @var RequestCreatorParams |
||
66 | */ |
||
67 | protected $params; |
||
68 | |||
69 | /** |
||
70 | * Associative array of messages (as keys) and versions (as values) that are present in the WSDL. |
||
71 | * |
||
72 | * @var array |
||
73 | */ |
||
74 | protected $messagesAndVersions = []; |
||
75 | |||
76 | /** |
||
77 | * Base Request Creator constructor. |
||
78 | * |
||
79 | * @param RequestCreatorParams $params |
||
80 | */ |
||
81 | public function __construct(RequestCreatorParams $params) |
||
82 | { |
||
83 | $this->params = $params; |
||
84 | $this->messagesAndVersions = $params->messagesAndVersions; |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * Create a request message for a given message with a set of options. |
||
89 | * |
||
90 | * @param string $messageName the message name as named in the WSDL |
||
91 | * @param RequestOptionsInterface $params |
||
92 | * @throws Struct\InvalidArgumentException When invalid input is detected during message creation. |
||
93 | * @throws InvalidMessageException when trying to create a request for a message that is not in your WSDL. |
||
94 | * @return mixed the created request |
||
95 | */ |
||
96 | public function createRequest($messageName, RequestOptionsInterface $params) |
||
97 | { |
||
98 | $this->checkMessageIsInWsdl($messageName); |
||
99 | |||
100 | $builder = $this->findBuilderForMessage($messageName); |
||
101 | |||
102 | $methodName = 'create'.str_replace("_", "", $messageName); |
||
103 | |||
104 | if (method_exists($builder, $methodName)) { |
||
105 | return $builder->$methodName($params, $this->getActiveVersionFor($messageName)); |
||
106 | } else { |
||
107 | throw new \RuntimeException('Message '.$methodName.' is not implemented in '.__CLASS__); |
||
108 | } |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * Security_SignOut |
||
113 | * |
||
114 | * @return Struct\Security\SignOut |
||
115 | */ |
||
116 | protected function createSecuritySignOut() |
||
120 | |||
121 | /** |
||
122 | * Create request object for Security_Authenticate message |
||
123 | * |
||
124 | * @param SecurityAuthenticateOptions $params |
||
125 | * @return Struct\Security\Authenticate |
||
126 | */ |
||
127 | protected function createSecurityAuthenticate(SecurityAuthenticateOptions $params) |
||
131 | |||
132 | /** |
||
133 | * Offer_VerifyOffer |
||
134 | * |
||
135 | * @param OfferVerifyOptions $params |
||
136 | * @return Struct\Offer\Verify |
||
137 | */ |
||
138 | protected function createOfferVerifyOffer(OfferVerifyOptions $params) |
||
147 | |||
148 | /** |
||
149 | * @param OfferConfirmAirOptions $params |
||
150 | * @return Struct\Offer\ConfirmAir |
||
151 | */ |
||
152 | protected function createOfferConfirmAirOffer(OfferConfirmAirOptions $params) |
||
156 | |||
157 | |||
158 | /** |
||
159 | * Offer_ConfirmHotelOffer |
||
160 | * |
||
161 | * @param OfferConfirmHotelOptions $params |
||
162 | * @return Struct\Offer\ConfirmHotel |
||
163 | */ |
||
164 | protected function createOfferConfirmHotelOffer(OfferConfirmHotelOptions $params) |
||
168 | |||
169 | /** |
||
170 | * @param OfferConfirmCarOptions $params |
||
171 | * @return Struct\Offer\ConfirmCar |
||
172 | */ |
||
173 | protected function createOfferConfirmCarOffer(OfferConfirmCarOptions $params) |
||
177 | |||
178 | /** |
||
179 | * Offer_CreateOffer |
||
180 | * |
||
181 | * Ok, I just realised this function name is a bit confusing. Sorry. |
||
182 | * |
||
183 | * @param OfferCreateOptions $params |
||
184 | * @return Struct\Offer\Create |
||
185 | */ |
||
186 | protected function createOfferCreateOffer(OfferCreateOptions $params) |
||
190 | |||
191 | /** |
||
192 | * Command_Cryptic |
||
193 | * |
||
194 | * @param CommandCrypticOptions $params |
||
195 | * @return Struct\Command\Cryptic |
||
196 | */ |
||
197 | protected function createCommandCryptic(CommandCrypticOptions $params) |
||
201 | |||
202 | /** |
||
203 | * Info_EncodeDecodeCity |
||
204 | * |
||
205 | * @param InfoEncodeDecodeCityOptions $params |
||
206 | * @return Struct\Info\EncodeDecodeCity |
||
207 | */ |
||
208 | protected function createInfoEncodeDecodeCity(InfoEncodeDecodeCityOptions $params) |
||
212 | |||
213 | /** |
||
214 | * MiniRule_GetFromPricingRec |
||
215 | * |
||
216 | * @param MiniRuleGetFromPricingRecOptions $params |
||
217 | * @return Struct\MiniRule\GetFromPricingRec |
||
218 | */ |
||
219 | protected function createMiniRuleGetFromPricingRec(MiniRuleGetFromPricingRecOptions $params) |
||
223 | |||
224 | /** |
||
225 | * MiniRule_GetFromPricing |
||
226 | * |
||
227 | * @param MiniRuleGetFromPricingOptions $params |
||
228 | * @return Struct\MiniRule\GetFromPricing |
||
229 | */ |
||
230 | protected function createMiniRuleGetFromPricing(MiniRuleGetFromPricingOptions $params) |
||
234 | |||
235 | /** |
||
236 | * Ticket_CreateTstFromPricing |
||
237 | * |
||
238 | * @param TicketCreateTstFromPricingOptions $params |
||
239 | * @return Struct\Ticket\CreateTSTFromPricing |
||
240 | */ |
||
241 | protected function createTicketCreateTSTFromPricing(TicketCreateTstFromPricingOptions $params) |
||
245 | |||
246 | /** |
||
247 | * Ticket_CreateTSMFromPricing |
||
248 | * |
||
249 | * @param TicketCreateTsmFromPricingOptions $params |
||
250 | * @return Struct\Ticket\CreateTSMFromPricing |
||
251 | */ |
||
252 | protected function createTicketCreateTSMFromPricing(TicketCreateTsmFromPricingOptions $params) |
||
256 | |||
257 | /** |
||
258 | * Ticket_DeleteTST |
||
259 | * |
||
260 | * @param TicketDeleteTstOptions $params |
||
261 | * @return Struct\Ticket\DeleteTST |
||
262 | */ |
||
263 | protected function createTicketDeleteTST(TicketDeleteTstOptions $params) |
||
267 | |||
268 | /** |
||
269 | * Ticket_DisplayTST |
||
270 | * |
||
271 | * @param TicketDisplayTstOptions $params |
||
272 | * @return Struct\Ticket\DisplayTST |
||
273 | */ |
||
274 | protected function createTicketDisplayTST(TicketDisplayTstOptions $params) |
||
278 | |||
279 | /** |
||
280 | * DocIssuance_IssueTicket |
||
281 | * |
||
282 | * @param DocIssuanceIssueTicketOptions $params |
||
283 | * @return Struct\DocIssuance\IssueTicket |
||
284 | */ |
||
285 | protected function createDocIssuanceIssueTicket(DocIssuanceIssueTicketOptions $params) |
||
289 | |||
290 | /** |
||
291 | * PriceXplorer_ExtremeSearch |
||
292 | * |
||
293 | * @param PriceXplorerExtremeSearchOptions $params |
||
294 | * @return Struct\PriceXplorer\ExtremeSearch |
||
295 | */ |
||
296 | protected function createPriceXplorerExtremeSearch(PriceXplorerExtremeSearchOptions $params) |
||
300 | |||
301 | /** |
||
302 | * SalesReports_DisplayQueryReport |
||
303 | * |
||
304 | * @param SalesReportsDisplayQueryReportOptions $params |
||
305 | * @return Struct\SalesReports\DisplayQueryReport |
||
306 | */ |
||
307 | protected function createSalesReportsDisplayQueryReport(SalesReportsDisplayQueryReportOptions $params) |
||
311 | |||
312 | /** |
||
313 | * Service_IntegratedPricing |
||
314 | * |
||
315 | * @param ServiceIntegratedPricingOptions $params |
||
316 | * @return Struct\Service\IntegratedPricing |
||
317 | */ |
||
318 | protected function createServiceIntegratedPricing(ServiceIntegratedPricingOptions $params) |
||
322 | |||
323 | /** |
||
324 | * Check if a given message is in the active WSDL(s). Throws exception if it isn't. |
||
325 | * |
||
326 | * @throws InvalidMessageException if message is not in loaded WSDL(s). |
||
327 | * @param string $messageName |
||
328 | */ |
||
329 | protected function checkMessageIsInWsdl($messageName) |
||
335 | |||
336 | /** |
||
337 | * Get the version number active in the WSDL for the given message |
||
338 | * |
||
339 | * @param string $messageName |
||
340 | * @return float|string |
||
341 | */ |
||
342 | protected function getActiveVersionFor($messageName) |
||
346 | |||
347 | /** |
||
348 | * Find the correct builder for a given message |
||
349 | * |
||
350 | * Message build methods in all builders must adhere to the |
||
351 | * 'create'<message name without underscores> logic as used in createRequest method. |
||
352 | * |
||
353 | * @param string $messageName |
||
354 | * @return Fare|Pnr|Queue|Base|Air |
||
355 | */ |
||
356 | protected function findBuilderForMessage($messageName) |
||
380 | } |
||
381 |