Skip to content

Commit 1fd1780

Browse files
committed
Clarify getLegacyScript per feedback.
1 parent 2041cc2 commit 1fd1780

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

migration.rst

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -312,14 +312,41 @@ somewhat like this::
312312

313313
class LegacyBridge
314314
{
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
316327
{
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+
}
320339

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+
{
321348
$p = $request->getPathInfo();
322-
$legacyScriptFilename = getScript($p);
349+
$legacyScriptFilename = LegacyBridge::getLegacyScript($p);
323350

324351
// Possibly (re-)set some env vars (e.g. to handle forms
325352
// posting to PHP_SELF):

0 commit comments

Comments
 (0)