PluginProbe
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution / 1.8.0
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution v1.8.0
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 / Proxy.php

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

63 lines 1.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Configures WP Proxies for the Symfony HTTP Client.
4 *
5 * @package SolidWP\Performance
6 */
7
8 declare( strict_types=1 );
9
10 namespace SolidWP\Performance\Preload;
11
12 use WP_HTTP_Proxy;
13
14 /**
15 * Configures WP Proxies for the Symfony HTTP Client.
16 *
17 * @package SolidWP\Performance
18 */
19 final class Proxy {
20
21 /**
22 * @var WP_HTTP_Proxy
23 */
24 private WP_HTTP_Proxy $proxy;
25
26 /**
27 * @param WP_HTTP_Proxy $proxy The WP Proxy object.
28 */
29 public function __construct( WP_HTTP_Proxy $proxy ) {
30 $this->proxy = $proxy;
31 }
32
33 /**
34 * Get a configured WP Proxy URL.
35 *
36 * @example username:password@192.168.12.14:8080
37 *
38 * @return string
39 */
40 public function url(): string {
41 if ( ! $this->proxy->is_enabled() ) {
42 return '';
43 }
44
45 $parts = [];
46
47 if ( $this->proxy->use_authentication() ) {
48 $parts[] = $this->proxy->authentication();
49 $parts[] = '@';
50 }
51
52 $parts[] = $this->proxy->host();
53
54 $port = $this->proxy->port();
55
56 if ( strlen( $port ) ) {
57 $parts[] = ':' . $port;
58 }
59
60 return implode( '', $parts );
61 }
62 }
63