-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUri.php
More file actions
27 lines (21 loc) · 925 Bytes
/
Uri.php
File metadata and controls
27 lines (21 loc) · 925 Bytes
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
<?php
declare(strict_types=1);
namespace Hyperf\OpenTelemetry\Support;
class Uri
{
public static function sanitize(string $uri, array $uriMask = []): string
{
$uuid = '/\/(?<=\/)([0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[0-9a-f]{4}-[0-9a-f]{12})(?=\/|$)/i';
$defaultPatterns = [
$uuid => '/{uuid}',
'/\/(?<=\/)[ED]\d{8}\d{12}[0-9a-zA-Z]{11}(?=\/|$)/' => '/{e2e_id}',
'/\/(?<=\/)[a-f0-9]{40}(?=\/|$)/i' => '/{sha1}',
'/\/(?<=\/)[A-Z]{3}-?\d[A-Z]?\d{2}(?=\/|$)/i' => '/{license_plate}',
'/\/(?<=\/)[0-9a-f]{16,24}(?=\/|$)/i' => '/{oid}',
'/\/(?<=\/)\d{4}-\d{2}-\d{2}(?=\/|$)/' => '/{date}',
'/\/(?<=\/)\d+(?=\/|$)/' => '/{number}',
];
$patterns = array_merge($defaultPatterns, $uriMask);
return preg_replace(array_keys($patterns), array_values($patterns), '/' . ltrim($uri, '/'));
}
}