composer require basster/legacy-bridge-bundle
config/bundles.php:
return [
// ...
Basster\LegacyBridgeBundle\BassterLegacyBridgeBundle::class => ['all' => true],
];
config/packages/basster_legacy_bridge.yaml:
basster_legacy_bridge:
legacy_path: '%kernel.project_dir%/legacy' # Path to your legacy PHP files
legacy_namespace: 'Legacy\\' # Optional: Namespace prefix for legacy files
legacy/old-script.php) in the configured path. Access it via Symfony’s front controller:
http://your-app.dev/old-script.php
The bundle auto-generates a route for it.bin/console debug:router for generated legacy routes.$container = $_SERVER['SYMFONY_CONTAINER'] ?? null;
if ($container) {
$service = $container->get('some_symfony_service');
}
Expose Legacy as Routes:
legacy_path (e.g., legacy/auth/login.php)./auth/login.php).legacy_namespace to group related legacy files (e.g., Legacy\Auth\Login).Inject Symfony Services:
$_SERVER['SYMFONY_CONTAINER']:
$userService = $_SERVER['SYMFONY_CONTAINER']->get('app.user_service');
URL Generation:
UrlGenerator in legacy templates:
$url = $_SERVER['SYMFONY_CONTAINER']->get('router')->generate('modern_route_name');
Shared Dependencies:
# config/services.yaml
services:
App\Service\LegacyUserBridge:
arguments:
$legacyUserClass: '%legacy_namespace%User'
$symfonyContainer: '@service_container'
Asset Handling:
assets component:
$assetUrl = $_SERVER['SYMFONY_CONTAINER']->get('assets')->getUrl('legacy/css/style.css');
config/routes.yaml:
legacy_routes:
resource: "@BassterLegacyBridgeBundle/Resources/config/routing/legacy.xml"
prefix: "/legacy"
kernel.request event listeners.WebTestCase:
$client = static::createClient();
$client->request('GET', '/legacy/old-script.php');
$this->assertEquals(200, $client->getResponse()->getStatusCode());
Case Sensitivity:
old-script.php ≠ Old-Script.php).Global State Pollution:
$_SESSION, register_globals). Isolate it by:
RequestStack for session access.global keywords in legacy files.Performance Overhead:
legacy/deep/nested/script.php). Use legacy_namespace to organize.Container Unavailability:
legacy_path).SYMFONY_CONTAINER is set in $_SERVER).Caching Issues:
php bin/console cache:clear) after adding/removing legacy files to update routes.legacy_path/filename.php.bin/console debug:router | grep legacy for generated routes.error_log(print_r($_SERVER, true)); // Check for 'SYMFONY_CONTAINER'
basster_legacy_bridge.debug config to log legacy route generation:
basster_legacy_bridge:
debug: true
Custom Route Loading: Override the route loader in a custom bundle:
// src/BassterLegacyBridgeBundle/DependencyInjection/Compiler/LegacyRoutePass.php
public function process(ContainerBuilder $container) {
$definition = $container->findDefinition('basster_legacy_bridge.route_loader');
$definition->addMethodCall('setCustomLoader', [[$this, 'loadCustomRoutes']]);
}
Pre/Post-Processing:
Hook into kernel.request to modify legacy requests/responses:
// src/EventListener/LegacyRequestListener.php
public function onKernelRequest(GetResponseEvent $event) {
$request = $event->getRequest();
if ($request->attributes->get('_legacy_route')) {
// Modify legacy request (e.g., add headers, rewrite paths)
}
}
Legacy Service Proxy: Create a proxy service to wrap legacy functions:
// src/Service/LegacyUserProxy.php
class LegacyUserProxy {
public function __construct(private ContainerInterface $container) {}
public function getUser() {
return $_SERVER['SYMFONY_CONTAINER']->get('legacy.user_service')->fetch();
}
}
legacy_path—use absolute paths to prevent security risks.legacy_namespace conflicts with existing classes, use fully qualified paths:
legacy_namespace: '\Legacy\\'
%kernel.environment% in legacy_path for environment-specific legacy directories:
legacy_path: '%kernel.project_dir%/legacy_%kernel.environment%'
How can I help you explore Laravel packages today?