@@ -28,6 +28,7 @@
Loading
28 28
use GuzzleHttp\HandlerStack;
29 29
use GuzzleHttp\MessageFormatter;
30 30
use function GuzzleHttp\Psr7\uri_for;
31 +
use GuzzleHttp\RequestOptions;
31 32
use Kreait\Clock;
32 33
use Kreait\Clock\SystemClock;
33 34
use Kreait\Firebase;
@@ -37,6 +38,7 @@
Loading
37 38
use Kreait\Firebase\Auth\IdTokenVerifier;
38 39
use Kreait\Firebase\Exception\InvalidArgumentException;
39 40
use Kreait\Firebase\Exception\RuntimeException;
41 +
use Kreait\Firebase\Http\HttpClientOptions;
40 42
use Kreait\Firebase\Http\Middleware;
41 43
use Kreait\Firebase\Project\ProjectId;
42 44
use Kreait\Firebase\Value\Email;
@@ -91,7 +93,11 @@
Loading
91 93
    /** @var bool */
92 94
    protected $guzzleDebugModeIsEnabled = false;
93 95
94 -
    /** @var string|null */
96 +
    /**
97 +
     * @var string|null
98 +
     *
99 +
     * @deprecated 5.7.0 Use {@see withClientOptions} instead.
100 +
     */
95 101
    protected $httpProxy;
96 102
97 103
    /** @var string */
@@ -109,11 +115,15 @@
Loading
109 115
    /** @var callable|null */
110 116
    protected $httpDebugLogMiddleware;
111 117
118 +
    /** @var HttpClientOptions */
119 +
    protected $httpClientOptions;
120 +
112 121
    public function __construct()
113 122
    {
114 123
        $this->clock = new SystemClock();
115 124
        $this->verifierCache = new InMemoryCache();
116 125
        $this->authTokenCache = new MemoryCacheItemPool();
126 +
        $this->httpClientOptions = HttpClientOptions::default();
117 127
    }
118 128
119 129
    /**
@@ -206,6 +216,14 @@
Loading
206 216
        return $factory;
207 217
    }
208 218
219 +
    public function withHttpClientOptions(HttpClientOptions $options): self
220 +
    {
221 +
        $factory = clone $this;
222 +
        $factory->httpClientOptions = $options;
223 +
224 +
        return $factory;
225 +
    }
226 +
209 227
    public function withHttpLogger(LoggerInterface $logger, ?MessageFormatter $formatter = null, ?string $logLevel = null, ?string $errorLogLevel = null): self
210 228
    {
211 229
        $formatter = $formatter ?: new MessageFormatter();
@@ -232,8 +250,11 @@
Loading
232 250
233 251
    public function withHttpProxy(string $proxy): self
234 252
    {
235 -
        $factory = clone $this;
236 -
        $factory->httpProxy = $proxy;
253 +
        $factory = $this->withHttpClientOptions(
254 +
            $this->httpClientOptions->withProxy($proxy)
255 +
        );
256 +
257 +
        $factory->httpProxy = $factory->httpClientOptions->proxy();
237 258
238 259
        return $factory;
239 260
    }
@@ -545,14 +566,18 @@
Loading
545 566
546 567
        // @codeCoverageIgnoreStart
547 568
        if ($this->guzzleDebugModeIsEnabled) {
548 -
            $config['debug'] = true;
569 +
            $config[RequestOptions::DEBUG] = true;
549 570
        }
550 571
        // @codeCoverageIgnoreEnd
551 572
552 -
        if ($this->httpProxy) {
553 -
            $config['proxy'] = $this->httpProxy;
573 +
        if ($proxy = $this->httpClientOptions->proxy()) {
574 +
            $config[RequestOptions::PROXY] = $proxy;
554 575
        }
555 576
577 +
        $config[RequestOptions::CONNECT_TIMEOUT] = $this->httpClientOptions->connectTimeout();
578 +
        $config[RequestOptions::READ_TIMEOUT] = $this->httpClientOptions->readTimeout();
579 +
        $config[RequestOptions::TIMEOUT] = $this->httpClientOptions->timeout();
580 +
556 581
        $handler = $config['handler'] ?? null;
557 582
558 583
        if (!($handler instanceof HandlerStack)) {

@@ -0,0 +1,148 @@
Loading
1 +
<?php
2 +
3 +
declare(strict_types=1);
4 +
5 +
namespace Kreait\Firebase\Http;
6 +
7 +
use Kreait\Firebase\Exception\InvalidArgumentException;
8 +
9 +
final class HttpClientOptions
10 +
{
11 +
    /**
12 +
     * The amount of seconds to wait while connecting to a server.
13 +
     *
14 +
     * Defaults to indefinitely.
15 +
     *
16 +
     * @var float
17 +
     */
18 +
    private $connectTimeout = \INF;
19 +
20 +
    /**
21 +
     * The amount of seconds to wait while reading a streamed body.
22 +
     *
23 +
     * Defaults to the value of the default_socket_timeout PHP ini setting.
24 +
     *
25 +
     * @var float
26 +
     */
27 +
    private $readTimeout;
28 +
29 +
    /**
30 +
     * The amount of seconds to wait for a full request (connect + transfer + read) to complete.
31 +
     *
32 +
     * Defaults to indefinitely.
33 +
     *
34 +
     * @var float
35 +
     */
36 +
    private $timeout = \INF;
37 +
38 +
    /**
39 +
     * The proxy that all requests should be passed through.
40 +
     *
41 +
     * @var string|null
42 +
     */
43 +
    private $proxy;
44 +
45 +
    private function __construct()
46 +
    {
47 +
        $this->readTimeout = ((float) \ini_get('default_socket_timeout')) ?: \INF;
48 +
    }
49 +
50 +
    public static function default(): self
51 +
    {
52 +
        return new self();
53 +
    }
54 +
55 +
    /**
56 +
     * The amount of seconds to wait while connecting to a server.
57 +
     *
58 +
     * Defaults to indefinitely.
59 +
     */
60 +
    public function connectTimeout(): float
61 +
    {
62 +
        return $this->connectTimeout;
63 +
    }
64 +
65 +
    /**
66 +
     * @param float $value the amount of seconds to wait while connecting to a server
67 +
     */
68 +
    public function withConnectTimeout(float $value): self
69 +
    {
70 +
        if ($value < 0) {
71 +
            throw new InvalidArgumentException('The connect timeout cannot be smaller than zero.');
72 +
        }
73 +
74 +
        $options = clone $this;
75 +
        $options->connectTimeout = $value;
76 +
77 +
        return $options;
78 +
    }
79 +
80 +
    /**
81 +
     * The amount of seconds to wait while reading a streamed body.
82 +
     *
83 +
     * Defaults to the value of the default_socket_timeout PHP ini setting.
84 +
     */
85 +
    public function readTimeout(): float
86 +
    {
87 +
        return $this->readTimeout;
88 +
    }
89 +
90 +
    /**
91 +
     * @param float $value the amount of seconds to wait while reading a streamed body
92 +
     */
93 +
    public function withReadTimeout(float $value): self
94 +
    {
95 +
        if ($value < 0) {
96 +
            throw new InvalidArgumentException('The read timeout cannot be smaller than zero.');
97 +
        }
98 +
99 +
        $options = clone $this;
100 +
        $options->readTimeout = $value;
101 +
102 +
        return $options;
103 +
    }
104 +
105 +
    /**
106 +
     * The amount of seconds to wait for a full request (connect + transfer + read) to complete.
107 +
     *
108 +
     * Defaults to indefinitely.
109 +
     */
110 +
    public function timeout(): float
111 +
    {
112 +
        return $this->timeout;
113 +
    }
114 +
115 +
    /**
116 +
     * @param float $value the amount of seconds to wait while reading a streamed body
117 +
     */
118 +
    public function withTimeout(float $value): self
119 +
    {
120 +
        if ($value < 0) {
121 +
            throw new InvalidArgumentException('The total timeout cannot be smaller than zero.');
122 +
        }
123 +
124 +
        $options = clone $this;
125 +
        $options->timeout = $value;
126 +
127 +
        return $options;
128 +
    }
129 +
130 +
    /**
131 +
     * The proxy that all requests should be passed through.
132 +
     */
133 +
    public function proxy(): ?string
134 +
    {
135 +
        return $this->proxy;
136 +
    }
137 +
138 +
    /**
139 +
     * @param string $value the proxy that all requests should be passed through
140 +
     */
141 +
    public function withProxy(string $value): self
142 +
    {
143 +
        $options = clone $this;
144 +
        $options->proxy = $value;
145 +
146 +
        return $options;
147 +
    }
148 +
}
Files Complexity Coverage
src/Firebase 1,400 95.93%
Project Totals (147 files) 1400 95.93%
1
comment:
2
  layout: "reach,diff"
3

4
coverage:
5
  status:
6
    project:
7
      default:
8
        informational: true
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading