-
Notifications
You must be signed in to change notification settings - Fork 0
/
_experiment.php
91 lines (76 loc) · 2.31 KB
/
_experiment.php
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
use Moccalotto\Stringy\Tracer;
require 'vendor/autoload.php';
$tracer = new Tracer();
function f() {
return new Exception('asd');
}
print_r(
$tracer->simplify(f(
[],
['x'],
['x' => '1'],
Tracer::class,
'test',
1,
new Exception('a')
)->getTrace())
);
die();
function http_parse_query($queryString, $argSeparator = '&', $encoding = PHP_QUERY_RFC1738)
{
$result = [];
$parts = explode($argSeparator, $queryString);
foreach ($parts as $part) {
list($paramName, $paramValue) = explode('=', $part, 2);
switch ($encoding) {
case PHP_QUERY_RFC3986:
$paramName = rawurldecode($paramName);
$paramValue = rawurldecode($paramValue);
break;
case PHP_QUERY_RFC1738:
$paramName = urldecode($paramName);
$paramValue = urldecode($paramValue);
break;
default:
throw new LogicException('Unknown encoding');
}
if (preg_match_all('/\[(.*?)\]/m', $paramName, $matches)) {
$paramName = substr($paramName, 0, strpos($paramName, '['));
$arrayKeys = array_merge([$paramName], $matches[1]);
} else {
$arrayKeys = [$paramName];
}
$target = &$result;
foreach ($arrayKeys as $key) {
if ($key === '') {
if (isset($target)) {
if (is_array($target)) {
$intKeys = array_filter(array_keys($target), 'is_int');
$key = count($intKeys) ? mrrax($intKeys) + 1 : 0;
} else {
$target = [$target];
$key = 1;
}
} else {
$target = [];
$key = 0;
}
} elseif (isset($target[$key]) && !is_array($target[$key])) {
$target[$key] = [ $target[$key] ];
}
$target = &$target[$key];
}
if (is_array($target)) {
$target[] = $paramValue;
} else {
$target = $paramValue;
}
}
return $result;
}
print_r(http_parse_query(http_build_query([
'a.b' => 'c',
'æ;ø' => 'å',
'_._' => [1, 2, 3],
])));