PHP code example of tmconsulting / hotelbook-php-sdk

1. Go to this page and download the library: Download tmconsulting/hotelbook-php-sdk 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/ */

    

tmconsulting / hotelbook-php-sdk example snippets


$config = [
    'url' => 'https://hotelbook.pro/xml',
    'login' => 'YOUR LOGIN',
    'password' => 'YOUR PASSSWORD'
];

//Require vendor
lbook class
use App\Hotelbook\Main;

//Create an instance of main class 
$hotelbook = new Main($config);


use Carbon\Carbon;

$from = Carbon::parse('08-07-2018');
$till = Carbon::parse('09-07-2018');

$result = $hotelbook->search(1, $from, $till, [new SearchPassenger(1, [2])]);


try {
    $result = $main->book(...someArguments);    
} catch (Exception $e)
{
    //Do something with the exception
}

//$result is a result of search request

if (!empty($result->getErrors()) {
 //Handle error
} 

$items = $result->getItems();
//Do something with items.

//You already have an instance of SDK, and it's stored in $main
$countries = $main->country();
//Now, in countries, you have a simple result.
$countiesArray = $countries->getItems();
//Now in $countiesArray you have an array of Countries.

$cities = $main->city();
$citiesArray = $cities->getItems();

//Get first country item from the DB.
$country = current($main->country()->getItems());
//Find all cities there.
$cities = $main->city($country);
//Get all available items.
$citiesArray = $cities->getItems();

composer