PHP code example of xmlworld / api-client

1. Go to this page and download the library: Download xmlworld/api-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

xmlworld / api-client example snippets


$xmlClient = new XMLClient(login: 'login', password: 'password');

$searchDetails = new SearchDetails(
	arrivalDate: '2023-09-01',	        // arrival date
	duration: 5,				// duration in days
	roomRequests: new RoomRequests(		// list of rooms
		RoomRequest::fromAges(2),
		RoomRequest::fromAges(
			1,		        // number of adults
			16,		        // age of first child (variadic)
			8,		        // age of second child
			2		        // age of third child
		),
	),
	properties: new Properties(19, 21),	// list of properties if searching for some
	propertyID: null,			// if only one we can use this param, but they exclude each other
	mealBasisID: 0,				// meal basis
	minStarRating: 0,			// filter by star rating
	minimumPrice: 0,			// filter by minimum price
	maximumPrice: 0				// filter by max price
);

try {
	$result = $xmlClient->search(searchDetails: $searchDetails);
} catch (Throwable $e) {

}

$bookingDetails = new BookDetails(
	arrivalDate: '2023-11-01',
	duration: 5,
	tradeReference: 'TEST_REF',
	totalPrice: 1040,
	leadGuest: new LeadGuest(
		firstName: 'TestLeadFName',
		lastName: 'TestLeadLName',
		title: 'Mr'
	),
	roomBookings: new RoomBookings(
		new RoomBooking(
			roomID: 20011,
			mealBasisID: 6,
			adults: 2,
			children: 0,
			infants: 0,
			guests: new Guests(
				new Guest(
					type: 'Adult',
					firstName: 'TestGuestFName',
					lastName: 'TestGuestLName',
					title: 'Mrs',
					age: null,
					nationality: 'French'
				)
			)
		),
	)
);


try {
	$result = $xmlClient->book(bookingDetails: $bookingDetails);
} catch (Throwable $e) {

}

try {
	$result = $xmlClient->booking(reference: $bookingReference);
} catch (Throwable $e) {
}

try {
	$result = $xmlClient->bookingUpdate(reference: $bookingReference, tradeReference: $tradeReference);
} catch (Throwable $e) {
}

try {
	$result = $xmlClient->cancel(reference: $bookingReference, reason: $cancellationReason);
} catch (Throwable $e) {
}

$env = XMLClient::ENV_DEV;

$xmlClient = new XMLClient(login: $login, password: $password, env: $env);


XMLClient::setDevURL('your own dev url');



$myLogger = function($payload){
	echo $payload;
};

//you can implement the Logger interface to inject your logging implementation in the client.
$logging = new class($myLogger) implements Logger
{
	protected Closure $myLogger;
	
	public function __construct(Closure $myLogger)
	{
		$this->myLogger = $myLogger;
	}

	public function logRequest(string $log): void
	{
		($this->myLogger)($log);
	}

	public function logResponse(int $statusCode, string $log): void
	{
		($this->myLogger)($log);
	}
};

$xmlClient = new XMLClient(login: $login, password: $password, env: $env, logger: $logging);