sylius-labs/polyfill-symfony-framework-bundle
PolyfillSymfonyFrameworkBundle provides a lightweight polyfill for Symfony’s FrameworkBundle, helping apps and libraries run when the full FrameworkBundle isn’t available. Useful for compatibility across Symfony versions and reduced dependencies.
Installation:
composer require sylius-labs/polyfill-symfony-framework-bundle
Add the bundle to config/bundles.php:
return [
// ...
SyliusLabs\PolyfillSymfonyFrameworkBundle\PolyfillSymfonyFrameworkBundle::class => ['all' => true],
];
First Use Case:
ContainerAwareCommand, HttpKernel, or other deprecated/removed components) but is not using Symfony FrameworkBundle directly (e.g., in a standalone Laravel app or a project with a custom kernel).ContainerAwareCommand (removed in Symfony 5+) but are using Symfony components outside the full framework.Polyfilling Symfony Components:
// Instead of:
use Symfony\Component\HttpKernel\KernelInterface;
// Use the polyfilled version (if available):
use SyliusLabs\PolyfillSymfonyFrameworkBundle\DependencyInjection\ContainerAwareCommand; // Hypothetical example
ContainerAwareCommand, HttpKernel traits).Laravel-Specific Use Cases:
ContainerAwareCommand to integrate Symfony-style commands in Laravel:
use SyliusLabs\PolyfillSymfonyFrameworkBundle\Command\ContainerAwareCommand;
class MyCommand extends ContainerAwareCommand {
protected function execute(InputInterface $input, OutputInterface $output) {
$this->getContainer()->get('some.service');
}
}
HttpKernel to bridge Symfony HTTP logic into Laravel middleware or routes.Dependency Injection:
$container = $this->getContainer(); // From ContainerAwareCommand
$service = $container->get('app.some_service');
Configuration:
config/services.php or config/kernel.php to include polyfilled Symfony configurations:
'framework' => [
'polyfill' => [
'enabled' => env('SYMFONY_POLYFILL_ENABLED', true),
// Custom polyfill settings
],
],
Symfony Version Mismatch:
composer.json aligns with this:
"require": {
"symfony/framework-bundle": "^5.4|^6.0"
}
Namespace Conflicts:
use SyliusLabs\PolyfillSymfonyFrameworkBundle\Command\ContainerAwareCommand as PolyfillContainerAwareCommand;
Mbstring Polyfill Conflict:
symfony/polyfill-mbstring (fixed in v1.1.1). Ensure you’re not double-polyfilling:
composer remove symfony/polyfill-mbstring
Deprecated Features:
ContainerAwareCommand) are deprecated in Symfony 6. Use at your own risk or migrate to alternatives like Command with explicit container access.Enable Debug Mode:
Add to config/services.php:
'framework' => [
'polyfill' => [
'debug' => env('APP_DEBUG', false),
],
],
This may expose polyfill-specific errors in Laravel’s debug bar.
Check Polyfill Coverage:
symfony/polyfill-*).Container Initialization:
public function boot() {
if ($this->app->has('polyfill_symfony_framework')) {
$this->app->boot();
}
}
Custom Polyfills:
namespace App\Polyfills;
use SyliusLabs\PolyfillSymfonyFrameworkBundle\PolyfillSymfonyFrameworkBundle as BaseBundle;
class CustomPolyfillBundle extends BaseBundle {
public function getPolyfills() {
return array_merge(parent::getPolyfills(), [
'App\Polyfills\MyMissingClass' => 'Symfony\Component\Some\MissingClass',
]);
}
}
config/bundles.php.Symfony Flex Integration:
symfony/flex recipes to automate polyfill configuration:
composer require symfony/flex
How can I help you explore Laravel packages today?