-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathURLInterpolator.php
More file actions
55 lines (51 loc) · 1.76 KB
/
URLInterpolator.php
File metadata and controls
55 lines (51 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
/*
* DeskPRO (r) has been developed by Deskpro Ltd. https://www.deskpro.com/
* a British company located in London, England.
*
* All source code and content Copyright (c) 2025, Deskpro Ltd.
*
* The license agreement under which this software is released
* can be found at https://www.deskpro.com/eula/
*
* By using this software, you acknowledge having read the license
* and agree to be bound thereby.
*
* Please note that DeskPRO is not free software. We release the full
* source code for our software because we trust our users to pay us for
* the huge investment in time and energy that has gone into both creating
* this software and supporting our customers. By providing the source code
* we preserve our customers' ability to modify, audit and learn from our
* work. We have been developing DeskPRO since 2001, please help us make it
* another decade.
*
* Like the work you see? Think you could make it better? We are always
* looking for great developers to join us: https://www.deskprocom/jobs/
*
* ~ Thanks, Everyone at Team Deskpro
*/
namespace Deskpro\API;
/**
* Modifies URLs by adding query strings and interpolates {placeholders}.
*/
class URLInterpolator implements URLInterpolatorInterface
{
/**
* {@inheritdoc}
*/
public function interpolate($url, array $params)
{
foreach($params as $key => $value) {
if (is_scalar($key) && is_scalar($value)) {
if (preg_match('/{' . preg_quote($key) . '}/', $url, $matches)) {
$url = str_replace($matches[0], $value, $url);
unset($params[$key]);
}
}
}
if (!empty($params)) {
$url .= '?' . http_build_query($params);
}
return $url;
}
}