PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.13.3
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.13.3
3.13.3 3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 All 261 releases
wpfunnels / vendor / league / glide / src / Urls / UrlBuilder.php

UrlBuilder.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.13.3, at vendor/league/glide/src/Urls/UrlBuilder.php

130 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace League\Glide\Urls;
4
5 use InvalidArgumentException;
6 use League\Glide\Signatures\SignatureInterface;
7
8 class UrlBuilder
9 {
10 /**
11 * The base URL.
12 *
13 * @var string
14 */
15 protected $baseUrl;
16
17 /**
18 * Whether the base URL is a relative domain.
19 *
20 * @var bool
21 */
22 protected $isRelativeDomain = false;
23
24 /**
25 * The HTTP signature used to sign URLs.
26 *
27 * @var SignatureInterface
28 */
29 protected $signature;
30
31 /**
32 * Create UrlBuilder instance.
33 *
34 * @param string $baseUrl The base URL.
35 * @param SignatureInterface|null $signature The HTTP signature used to sign URLs.
36 */
37 public function __construct($baseUrl = '', ?SignatureInterface $signature = null)
38 {
39 $this->setBaseUrl($baseUrl);
40 $this->setSignature($signature);
41 }
42
43 /**
44 * Set the base URL.
45 *
46 * @param string $baseUrl The base URL.
47 *
48 * @return void
49 */
50 public function setBaseUrl($baseUrl)
51 {
52 if ('//' === substr($baseUrl, 0, 2)) {
53 $baseUrl = 'http:'.$baseUrl;
54 $this->isRelativeDomain = true;
55 }
56
57 $this->baseUrl = rtrim($baseUrl, '/');
58 }
59
60 /**
61 * Set the HTTP signature.
62 *
63 * @param SignatureInterface|null $signature The HTTP signature used to sign URLs.
64 *
65 * @return void
66 */
67 public function setSignature(?SignatureInterface $signature = null)
68 {
69 $this->signature = $signature;
70 }
71
72 /**
73 * Get the URL.
74 *
75 * @param string $path The resource path.
76 * @param array $params The manipulation parameters.
77 *
78 * @return string The URL.
79 */
80 public function getUrl($path, array $params = [])
81 {
82 $parts = parse_url($this->baseUrl.'/'.trim($path, '/'));
83
84 if (false === $parts) {
85 throw new InvalidArgumentException('Not a valid path.');
86 }
87
88 $parts['path'] = '/'.trim($parts['path'], '/');
89
90 if ($this->signature) {
91 $params = $this->signature->addSignature($parts['path'], $params);
92 }
93
94 return $this->buildUrl($parts, $params);
95 }
96
97 /**
98 * Build the URL.
99 *
100 * @param array $parts The URL parts.
101 * @param array $params The manipulation parameters.
102 *
103 * @return string The built URL.
104 */
105 protected function buildUrl($parts, $params)
106 {
107 $url = '';
108
109 if (isset($parts['host'])) {
110 if ($this->isRelativeDomain) {
111 $url .= '//'.$parts['host'];
112 } else {
113 $url .= $parts['scheme'].'://'.$parts['host'];
114 }
115
116 if (isset($parts['port'])) {
117 $url .= ':'.$parts['port'];
118 }
119 }
120
121 $url .= $parts['path'];
122
123 if (count($params)) {
124 $url .= '?'.http_build_query($params);
125 }
126
127 return $url;
128 }
129 }
130