@@ -312,14 +312,41 @@ somewhat like this::
312
312
313
313
class LegacyBridge
314
314
{
315
- public static function handleRequest(Request $request, Response $response, string $publicDirectory): ?string
315
+
316
+ /**
317
+ * Map the incoming request to the right file. This is the
318
+ * key function of the LegacyBridge.
319
+ *
320
+ * Sample code only. Your implementation will vary, depending on the
321
+ * architecture of the legacy code and how it's executed.
322
+ *
323
+ * If your mapping is complicated, you may want to write unit tests
324
+ * to verify your logic, hence this is public static.
325
+ */
326
+ public static function getLegacyScript(string $requestPathInfo): string
316
327
{
317
- // Figure out how to map to the needed script file
318
- // from the existing application.
319
- function getScript($requestPathInfo) { ... }
328
+ $legacyRoot = __DIR__ . '/../';
329
+
330
+ // Map a route to a legacy script:
331
+ if ($requestPathInfo == '/customer/') {
332
+ return "{$legacyRoot}src/customers/list.php";
333
+ }
334
+
335
+ // Map a direct file call, e.g. an ajax call:
336
+ if ($requestPathInfo == 'inc/ajax_cust_details.php') {
337
+ return "{$legacyRoot}inc/ajax_cust_details.php";
338
+ }
320
339
340
+ // ... etc.
341
+
342
+ throw new \Exception("Unhandled legacy mapping for $requestPathInfo");
343
+ }
344
+
345
+
346
+ public static function handleRequest(Request $request, Response $response, string $publicDirectory): ?string
347
+ {
321
348
$p = $request->getPathInfo();
322
- $legacyScriptFilename = getScript ($p);
349
+ $legacyScriptFilename = LegacyBridge::getLegacyScript ($p);
323
350
324
351
// Possibly (re-)set some env vars (e.g. to handle forms
325
352
// posting to PHP_SELF):
0 commit comments