PluginProbe
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution / trunk
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution vtrunk
2.0.1 trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.5.0 1.6.0 1.6.1 1.7.0 1.7.1 1.8.0 1.9.0 2.0.0
solid-performance / src / Performance / Preload / Client.php

Client.php in Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution trunk, at src/Performance/Preload/Client.php

96 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The Preloader client.
4 *
5 * @package SolidWP\Performance
6 */
7
8 declare( strict_types=1 );
9
10 namespace SolidWP\Performance\Preload;
11
12 use SolidWP\Performance\Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
13 use SolidWP\Performance\Symfony\Contracts\HttpClient\HttpClientInterface;
14 use SolidWP\Performance\Symfony\Contracts\HttpClient\ResponseInterface;
15
16 /**
17 * The Preloader client.
18 *
19 * @package SolidWP\Performance
20 */
21 class Client {
22
23 /**
24 * The underlying HTTP client.
25 *
26 * @var HttpClientInterface
27 */
28 private HttpClientInterface $client;
29
30 /**
31 * @var Uri
32 */
33 private Uri $uri;
34
35 /**
36 * @param HttpClientInterface $client The underlying HTTP client.
37 * @param Uri $uri The URI object.
38 */
39 public function __construct( HttpClientInterface $client, Uri $uri ) {
40 $this->client = $client;
41 $this->uri = $uri;
42 }
43
44 /**
45 * Get the underlying HTTP client.
46 *
47 * @return HttpClientInterface
48 */
49 public function client(): HttpClientInterface {
50 return $this->client;
51 }
52
53 /**
54 * Perform a GET request.
55 *
56 * @param string $path The relative path to access to the WordPress home URL.
57 * @param array<string, mixed> $params The query string parameters to pass to the request.
58 * @param array<string, string> $headers Additional headers to send along with the request.
59 * @param array<string, mixed> $options Additional Symfony HTTP Client options.
60 *
61 * @throws TransportExceptionInterface When an error occurs at the transport level, e.g. DNS failure, network failure etc...
62 *
63 * @return ResponseInterface
64 */
65 public function get( string $path, array $params = [], array $headers = [], array $options = [] ): ResponseInterface {
66 return $this->request(
67 $path,
68 'GET',
69 array_merge(
70 $options,
71 [
72 'query' => $params,
73 'headers' => $headers,
74 ],
75 )
76 );
77 }
78
79 /**
80 * Send a request.
81 *
82 * @param string $path The relative path or URL to make relative to access to the WordPress home URL.
83 * @param string $method The Request Method, e.g. GET, POST, DELETE etc...
84 * @param array<string, mixed> $options Additional Symfony HTTP Client options.
85 *
86 * @throws TransportExceptionInterface When an error occurs at the transport level, e.g. DNS failure, network failure etc...
87 *
88 * @return ResponseInterface
89 */
90 public function request( string $path, string $method = 'GET', array $options = [] ): ResponseInterface {
91 $uri = $this->uri->make_relative( $path );
92
93 return $this->client->request( $method, $uri, $options );
94 }
95 }
96