PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.8
Booking for Appointments and Events Calendar – Amelia v2.4.8
2.4.9 2.4.8 2.4.7 2.4.6 2.4.5 2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / src / Infrastructure / ContainerConfig / request.php
ameliabooking / src / Infrastructure / ContainerConfig Last commit date
application.services.php 3 months ago command.bus.php 1 week ago container.php 2 months ago domain.event.bus.php 1 year ago domain.services.php 1 year ago infrastructure.services.php 1 week ago infrastructure.user.php 1 year ago repositories.php 7 months ago request.php 1 week ago
request.php
122 lines
1 <?php
2
3 use AmeliaBooking\Infrastructure\Common\Container;
4 use Slim\Factory\ServerRequestCreatorFactory;
5
6 $entries['request'] = function (Container $c) {
7 $creator = ServerRequestCreatorFactory::create();
8
9 $serverRequest = $creator->createServerRequestFromGlobals();
10
11 $curUri = $serverRequest->getUri();
12
13 // fix callback url for Razorpay payment through link since Razorpay encodes callback urls
14 $queryWithPlaceholderFixes = str_replace(
15 '__payments__callback',
16 '/payments/callback',
17 $curUri->getQuery()
18 );
19
20 // fix callback url for Stripe redirect payment methods since Stripe encodes callback urls
21 $queryWithPlaceholderFixes = str_replace(
22 '__payment__stripe__callback',
23 '/payment/stripe/callback',
24 $queryWithPlaceholderFixes
25 );
26
27 // fix callback url for whatsapp webhooks
28 $queryWithPlaceholderFixes = str_replace(
29 '__notifications__whatsapp__webhook',
30 '/notifications/whatsapp/webhook',
31 $queryWithPlaceholderFixes
32 );
33
34 [$newPath, $newQuery] = (function ($queryWithPlaceholderFixes, array $get) {
35 if (isset($get['call']) && is_string($get['call']) && $get['call'] !== '') {
36 $callPath = str_replace(
37 '__payments__callback',
38 '/payments/callback',
39 $get['call']
40 );
41 $callPath = str_replace(
42 '__payment__stripe__callback',
43 '/payment/stripe/callback',
44 $callPath
45 );
46 $callPath = str_replace(
47 '__notifications__whatsapp__webhook',
48 '/notifications/whatsapp/webhook',
49 $callPath
50 );
51
52 $queryParams = $get;
53 unset($queryParams['action'], $queryParams['call']);
54
55 return [$callPath, http_build_query($queryParams)];
56 }
57
58 $newRoute = str_replace(
59 ['XDEBUG_SESSION_START=PHPSTORM&' . AMELIA_ACTION_SLUG, AMELIA_ACTION_SLUG],
60 '',
61 $queryWithPlaceholderFixes
62 );
63
64 $newPath = strpos($newRoute, '&') ? substr(
65 $newRoute,
66 0,
67 strpos($newRoute, '&')
68 ) : $newRoute;
69
70 $newQuery = strpos($newRoute, '&') ? substr(
71 $newRoute,
72 strpos($newRoute, '&') + 1
73 ) : '';
74
75 return [$newPath, $newQuery];
76 })($queryWithPlaceholderFixes, $_GET);
77
78 $request = $serverRequest->withUri(
79 $curUri
80 ->withPath($newPath)
81 ->withQuery($newQuery)
82 );
83
84 $queryParams = $request->getQueryParams();
85
86 if (!empty($queryParams['showAmeliaErrors'])) {
87 ini_set('display_errors', 1);
88 ini_set('display_startup_errors', 1);
89 error_reporting(E_ALL);
90 }
91
92 // Some hosts/WAFs strip Content-Type on admin-ajax POST requests. Slim then skips JSON
93 // parsing (parsed body stays null or []), even though the request body stream has valid JSON.
94 if ($request->getMethod() === 'POST') {
95 $contentType = $request->getHeaderLine('Content-Type');
96 $parsedBody = $request->getParsedBody();
97 $missingJsonContentType = $contentType === '' || stripos($contentType, 'json') === false;
98 $parsedBodyIsEmpty = $parsedBody === null || $parsedBody === [];
99
100 if ($missingJsonContentType && $parsedBodyIsEmpty) {
101 $body = $request->getBody();
102
103 if ($body->isSeekable()) {
104 $body->rewind();
105 }
106
107 $raw = (string) $body;
108 $trimmed = ltrim($raw);
109
110 if ($trimmed !== '' && ($trimmed[0] === '{' || $trimmed[0] === '[')) {
111 $json = json_decode($trimmed, true);
112
113 if (is_array($json)) {
114 $request = $request->withParsedBody($json);
115 }
116 }
117 }
118 }
119
120 return $request;
121 };
122