/amadeus-php

PHP library for the Amadeus Self-Service travel APIs

Primary LanguagePHPApache License 2.0Apache-2.0

Amadeus PHP

Latest Stable Version

This library provides implementation of Client to interact with Amadeus Self-Service API on PHP.

Installation via Composer

composer require therealartz/amadeus-php

Quickstart

Setup client

use Amadeus\Client;

$apiKey = 'api_key';
$apiSecret = 'api_secret';

$client = new Client($apiKey, $apiSecret);

Authentication will be performed before first request, but token needs to be stored on application side and putted in Client on each request.

// TODO: Provide some example

Shopping Flight Offers

use Amadeus\Request\Shopping\FlightOffersRequestOptions;

$request = new FlightOffersRequestOptions(
    $origin = 'JFK',
    $destination = 'ORD',
    $departureDate = \DateTimeImmutable::createFromFormat('Y-m-d', '2020-03-01'), // Any \DateTimeInterface
    $returnDate = null,
    $adults = 2,
    $children = 0,
    $infants = 0,
    $seniors = 0,
    $travelClass = null,
    $nonStop = false,
    $currency = 'USD',
    $maxResults = 50,
    $maxPrice = null,
    $arrivalBy = null,
    $returnBy = null,
    $includeAirlines = [],
    $excludeAirlines = []
);

$results = $client->shoppingFlightOffers($request);

Logging

To enable library logging when creating Client pass an instance of Psr\Log\LoggerInterface as fourth argument (optional):

use Amadeus\Client;
use Monolog\Logger;

$client = new Client(
    $apiKey = 'api_key',
    $apiSecret = 'api_secret',
    $isProduction = false,
    $logger = new Logger(
        'amadeus', 
        [
            new Monolog\Handler\StreamHandler(__DIR__ . '/var/log/amadeus.log')
        ]
    ),
);

Caching

To enable built-in library cache when creating Client pass an instance of Symfony\Contracts\Cache\CacheInterface (PSR-16 not supported yet) as fifth argument (optional):

use Amadeus\Client;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;

$client = new Client(
    $apiKey = 'api_key',
    $apiSecret = 'api_secret',
    $isProduction = false,
    $logger = null,
    $cache = new FilesystemAdapter('amadeus', 0, __DIR__ . '/var/cache'),
);