Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Travelport SoapClient
<?php
/**
* File containing the overriding class for the SoapClient used in the WsdlClass class
* @package Travelport
* @subpackage Structs
* @author WsdlToPhp Team <contact@wsdltophp.com>
* @date 17-02-2014
*/
/**
* Class that overrides the native SoapClient in order to modify its behavior especially before sending the request
* @package Travelport
* @subpackage Structs
* @author WsdlToPhp Team <contact@wsdltophp.com>
* @date 17-02-2014
*/
class TravelportSoapClient extends SoapClient
{
/**
* Parameter sent in the request
* @var TravelportStructAirExchangeQuoteReq|TravelportStructAirExchangeReq|TravelportStructAirExchangeTicketingReq|TravelportStructAirFareDisplayReq|TravelportStructAirFareRulesReq|TravelportStructAirMerchandisingDetailsReq|TravelportStructAirMerchandisingOfferAvailabilityReq|TravelportStructAirPrePayReq|TravelportStructAirPriceReq|TravelportStructAirRefundQuoteReq|TravelportStructAirRefundReq|TravelportStructAirRepriceReq|TravelportStructAirRetrieveDocumentReq|TravelportStructAirTicketingReq|TravelportStructAirUpsellSearchReq|TravelportStructAirVoidDocumentReq|TravelportStructAvailabilitySearchReq|TravelportStructEMDIssuanceReq|TravelportStructEMDRetrieveReq|TravelportStructFlightDetailsReq|TravelportStructFlightInformationReq|TravelportStructFlightTimeTableReq|TravelportStructLowFareSearchAsynchReq|TravelportStructLowFareSearchReq|TravelportStructRetrieveLowFareSearchReq|TravelportStructScheduleSearchReq|TravelportStructSeatMapReq
*/
private $parameter = null;
/**
* Last sent XML request
* @var string
*/
private $__lastRequest = null;
/**
* Override native __call method to catch informations
* @see SoapClient::__call()
* @uses TravelportSoapClient::setParameter()
* @param string $_functionName
* @param array $_arguments
* @return mixed
*/
public function __call($_functionName,$_arguments)
{
$this->setParameter($_arguments[0]);
parent::__call($_functionName,$_arguments);
}
/**
* Override native __call method to modify the XML request content
* @see SoapClient::__doRequest()
* @uses TravelportSoapClient::handleXmlRequest()
* @param string $_request
* @param string $_location
* @param string $_action
* @param string $_version
* @param int $_oneWay
* @return mixed
*/
public function __doRequest($_request,$_location,$_action,$_version,$_oneWay = null)
{
$this->handleXmlRequest($_request);
$response = parent::__doRequest($_request,$_location,$_action,$_version,$_oneWay);
return $response;
}
/**
* Returns last XML request
* @see SoapClient::__getLastRequest()
* @return string
*/
public function __getLastRequest()
{
return $this->__lastRequest;
}
/**
* Sets last XML request
* @param string $_lastRequest
* @return string
*/
public function __setLastRequest($_lastRequest)
{
return ($this->__lastRequest = $_lastRequest);
}
/**
* Returns prefix name used for generated classes (package name actually)
* @return string
*/
public static function getPrefix()
{
return strpos(__CLASS__,'SoapClient') > 0?substr(__CLASS__,0,strpos(__CLASS__,'SoapClient')):null;
}
/**
* Sets the parameter
* @uses TravelportSoapClient::getPrefix()
* @param TravelportStructAirExchangeQuoteReq|TravelportStructAirExchangeReq|TravelportStructAirExchangeTicketingReq|TravelportStructAirFareDisplayReq|TravelportStructAirFareRulesReq|TravelportStructAirMerchandisingDetailsReq|TravelportStructAirMerchandisingOfferAvailabilityReq|TravelportStructAirPrePayReq|TravelportStructAirPriceReq|TravelportStructAirRefundQuoteReq|TravelportStructAirRefundReq|TravelportStructAirRepriceReq|TravelportStructAirRetrieveDocumentReq|TravelportStructAirTicketingReq|TravelportStructAirUpsellSearchReq|TravelportStructAirVoidDocumentReq|TravelportStructAvailabilitySearchReq|TravelportStructEMDIssuanceReq|TravelportStructEMDRetrieveReq|TravelportStructFlightDetailsReq|TravelportStructFlightInformationReq|TravelportStructFlightTimeTableReq|TravelportStructLowFareSearchAsynchReq|TravelportStructLowFareSearchReq|TravelportStructRetrieveLowFareSearchReq|TravelportStructScheduleSearchReq|TravelportStructSeatMapReq $_parameter
* @return null|TravelportStructAirExchangeQuoteReq|TravelportStructAirExchangeReq|TravelportStructAirExchangeTicketingReq|TravelportStructAirFareDisplayReq|TravelportStructAirFareRulesReq|TravelportStructAirMerchandisingDetailsReq|TravelportStructAirMerchandisingOfferAvailabilityReq|TravelportStructAirPrePayReq|TravelportStructAirPriceReq|TravelportStructAirRefundQuoteReq|TravelportStructAirRefundReq|TravelportStructAirRepriceReq|TravelportStructAirRetrieveDocumentReq|TravelportStructAirTicketingReq|TravelportStructAirUpsellSearchReq|TravelportStructAirVoidDocumentReq|TravelportStructAvailabilitySearchReq|TravelportStructEMDIssuanceReq|TravelportStructEMDRetrieveReq|TravelportStructFlightDetailsReq|TravelportStructFlightInformationReq|TravelportStructFlightTimeTableReq|TravelportStructLowFareSearchAsynchReq|TravelportStructLowFareSearchReq|TravelportStructRetrieveLowFareSearchReq|TravelportStructScheduleSearchReq|TravelportStructSeatMapReq
*/
public function setParameter($_parameter)
{
$prefix = self::getPrefix();
if(!empty($prefix) && is_object($_parameter) && is_subclass_of($_parameter,"{$prefix}WsdlClass"))
return ($this->parameter = $_parameter);
else
return ($this->parameter = null);
}
/**
* Returns the parameter being sent as request
* @return TravelportStructAirExchangeQuoteReq|TravelportStructAirExchangeReq|TravelportStructAirExchangeTicketingReq|TravelportStructAirFareDisplayReq|TravelportStructAirFareRulesReq|TravelportStructAirMerchandisingDetailsReq|TravelportStructAirMerchandisingOfferAvailabilityReq|TravelportStructAirPrePayReq|TravelportStructAirPriceReq|TravelportStructAirRefundQuoteReq|TravelportStructAirRefundReq|TravelportStructAirRepriceReq|TravelportStructAirRetrieveDocumentReq|TravelportStructAirTicketingReq|TravelportStructAirUpsellSearchReq|TravelportStructAirVoidDocumentReq|TravelportStructAvailabilitySearchReq|TravelportStructEMDIssuanceReq|TravelportStructEMDRetrieveReq|TravelportStructFlightDetailsReq|TravelportStructFlightInformationReq|TravelportStructFlightTimeTableReq|TravelportStructLowFareSearchAsynchReq|TravelportStructLowFareSearchReq|TravelportStructRetrieveLowFareSearchReq|TravelportStructScheduleSearchReq|TravelportStructSeatMapReq
*/
public function getParameter()
{
return $this->parameter;
}
/**
* Returns parameter name useful for the XML request
* @uses TravelportSoapClient::getPrefix()
* @uses TravelportSoapClient::getParameter()
* @return string
*/
public function getParameterName()
{
$prefix = self::getPrefix();
$parameter = $this->getParameter();
$name = '';
if(!empty($prefix) && $parameter != null)
$name = str_replace("{$prefix}Struct",'',$parameter->__toString());
return $name;
}
/**
* Handle XML request before being sent
* @uses TravelportSoapClient::getParameterName()
* @uses TravelportSoapClient::__setLastRequest()
* @param string $_xmlRequest
* @return string
*/
private function handleXmlRequest(&$_xmlRequest)
{
if($this->getParameterName() != '')
{
/**
* Remove type reference for current parameter element
*/
$_xmlRequest = str_replace(" xsi:type=\"ns2:{$this->getParameterName()}\"",'',$_xmlRequest);
/**
* Update request type
*/
$_xmlRequest = str_replace('ns2:AirRepriceReq',"ns2:{$this->getParameterName()}",$_xmlRequest);
}
$this->__setLastRequest($_xmlRequest);
}
/**
* Returns current class name
* @return string
*/
public function __toString()
{
return __CLASS__;
}
}
@mikaelcom

This comment has been minimized.

Copy link
Owner Author

commented Mar 6, 2014

This class can be used to handle Travelport soap request that fails. The main goal is to make use of this class that overrides the SoapClient class in order to modify the generated XML request. We replace the main parameter element tag name by the current parameter type.

Don't forget to update:

  • the class name based on your generated package name
  • the handleXmlRequest method by replacing AirRepriceReq by the default element tag name that is used by default by the SoapClient
  • load this class before the calls are sent

Feel free to ask help at contact@wsdltophp.com

@farhan2986

This comment has been minimized.

Copy link

commented Mar 7, 2014

need to return the parent::__call otherwise gives nothing
public function __call($_functionName,$_arguments)
{
$this->setParameter($_arguments[0]);
return parent::__call($_functionName,$_arguments);
}

@farhan2986

This comment has been minimized.

Copy link

commented Mar 7, 2014

@mikaelcom SoapClient Returns NULL, but getLastResponse() returns XML. It is working fine for one type of request but for other type of requests returns nothing e.g
serviceHotelSearchAvailabilityReq() returns the required response
serviceHotelMediaLinksReq() returns nothing even response is coming in __doRequest function __call returns nothing

any idea why SoapClient is not converting MedialLinkReq response into object. thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.