I'm trying to start migrating my legacy project to Symfony, piece by piece (Strangler Application). I followed this documentation, but I can only load my home URL /
of my legacy application. Other URL's will give me a 404 even before I get to the LegacyBridge
class.
What do I miss?
EDIT:
Probably people don't understand my question. I have no issues starting my Symfony project. I'm trying to build a Strangler Application, slowly migrating my legacy code to Symfony. So my legacy code and Symfony application are running side by side. But everything is loaded through the frontend controller of Symfony.
So I modified the index.php from Symfony public/index.php
.
I added a LegacyBridge class to the frontend controller of Symfony:
<?php
// public/index.php
use App\Kernel;
use App\LegacyBridge;
use Symfony\Component\Debug\Debug;
use Symfony\Component\HttpFoundation\Request;
require dirname(__DIR__).'/config/bootstrap.php';
/*
* The kernel will always be available globally, allowing you to
* access it from your existing application and through it the
* service container. This allows for introducing new features in
* the existing application.
*/
global $kernel;
if ($_SERVER['APP_DEBUG']) {
umask(0000);
Debug::enable();
}
if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? $_ENV['TRUSTED_PROXIES'] ?? false) {
Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
}
if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? $_ENV['TRUSTED_HOSTS'] ?? false) {
Request::setTrustedHosts([$trustedHosts]);
}
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
/*
* LegacyBridge will take care of figuring out whether to boot up the
* existing application or to send the Symfony response back to the client.
*/
$scriptFile = LegacyBridge::prepareLegacyScript($request, $response, __DIR__);
if ($scriptFile !== null) {
require $scriptFile;
} else {
$response->send();
}
$kernel->terminate($request, $response);
I already get a 404 on line $response = $kernel->handle($request);
.
<?php
//src/LegacyBridge.php
namespace App;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class LegacyBridge
{
public static function prepareLegacyScript(Request $request, Response $response, string $publicDirectory)
{
// If Symfony successfully handled the route, you do not have to do anything.
if (false === $response->isNotFound()) {
return;
}
// Figure out how to map to the needed script file
// from the existing application and possibly (re-)set
// some env vars.
$dir = $request->server->get('SERVER_NAME');
$dir = str_replace('.test', '.nl', $dir);
$legacyScriptFilename = realpath($publicDirectory . '/../../' . $dir . '/index.php');
return $legacyScriptFilename;
}
}