1<?php
2namespace Kunnu\Dropbox\Http\Clients;
3
4use InvalidArgumentException;
5use GuzzleHttp\Client as Guzzle;
6
7/**
8 * DropboxHttpClientFactory
9 */
10class DropboxHttpClientFactory
11{
12    /**
13     * Make HTTP Client
14     *
15     * @param  \Kunnu\Dropbox\Http\Clients\DropboxHttpClientInterface|\GuzzleHttp\Client|null $handler
16     *
17     * @return \Kunnu\Dropbox\Http\Clients\DropboxHttpClientInterface
18     */
19    public static function make($handler)
20    {
21        //No handler specified
22        if (!$handler) {
23            return new DropboxGuzzleHttpClient();
24        }
25
26        //Custom Implementation, maybe.
27        if ($handler instanceof DropboxHttpClientInterface) {
28            return $handler;
29        }
30
31        //Handler is a custom configured Guzzle Client
32        if ($handler instanceof Guzzle) {
33            return new DropboxGuzzleHttpClient($handler);
34        }
35
36        //Invalid handler
37        throw new InvalidArgumentException('The http client handler must be an instance of GuzzleHttp\Client or an instance of Kunnu\Dropbox\Http\Clients\DropboxHttpClientInterface.');
38    }
39}
40