symplify/php-config-printer
Print Symfony service and parameter configs to clean PHP files using nikic/php-parser. Generate output for configured services only or full configs (e.g., from YAML arrays) via SmartPhpConfigPrinter and YamlToPhpConverter. Ideal for config transformations and automation.
ContainerConfigurator and services.yaml structure. Laravel’s service container (based on Illuminate/Container) has fundamentally different APIs, including:
services.yaml support (configs are PHP-based).Autowire trait vs. Symfony’s autowire: true).tags: in Symfony vs. app()->tag() in Laravel).nikic/php-parser, which is compatible with Laravel (used in tools like PestPHP or Laravel IDE Helper). However, the Symfony-specific parsing logic (e.g., handling ContainerConfigurator) won’t translate directly.app()->bind()).// Step 1: Parse Symfony-style config (e.g., from a YAML file)
$converter = new YamlToPhpConverter();
$services = $converter->convertYamlArray(file_get_contents('services.yaml'));
// Step 2: Manually bind to Laravel's container
foreach ($services as $id => $config) {
if (isset($config['class'])) {
app()->bind($id, fn() => new $config['class']);
}
// Handle other configs (e.g., arguments, tags) with custom logic
}
tags: in Symfony → app()->tag() in Laravel).public/private vs. Laravel’s when()).lazy: true vs. Laravel’s defer()).symfony/dependency-injection) for a non-Symfony project adds unnecessary complexity and potential conflicts.ContainerConfigurator), which don’t map 1:1 to Laravel.register()/boot() methods).php artisan config:export) rather than coupling it to Laravel’s core.spatie/laravel-config-array, custom Artisan commands) before committing to this package.config/services.php directly) achieve the same goals?spatie/laravel-config-array) that could replace this?phpstan/phpdoc-parser) be lighter-weight for Laravel’s needs?Container reflection be used instead of Symfony’s parser?nikic/php-parser: Compatible and widely used in Laravel ecosystems (e.g., PestPHP).ContainerConfigurator equivalent in Laravel.spatie/laravel-config-array to export config/ files to arrays.app()->make() or app()->bound() for runtime analysis.app/Providers/AppServiceProvider.php or config/services.php.Phase 1: Isolation (Standalone Script)
services.yaml).YamlToPhpConverter.# Run outside Laravel's context
composer require symplify/php-config-printer --dev
vendor/bin/php-config-printer parse services.yaml > exported_services.php
Phase 2: Adapter Layer (Laravel Integration)
class SymfonyToLaravelAdapter {
public function __construct(private Container $container) {}
public function registerFromSymfonyConfig(array $symfonyServices): void {
foreach ($symfonyServices as $id => $config) {
if (isset($config['class'])) {
$this->container->bind($id, fn() => new $config['class']);
}
// Handle arguments, tags, etc.
if (isset($config['arguments'])) {
$this->container->when($id)->needs('$arg')->give($config['arguments'][0]);
}
// TODO: Map tags, interfaces, etc.
}
}
}
Phase 3: Artisan Command (User-Friendly)
Artisan command for easy invocation:
// app/Console/Commands/ExportSymfonyServices.php
class ExportSymfonyServices extends Command {
protected $signature = 'config:export-symfony {file}';
protected $description = 'Export Symfony services to Laravel-compatible PHP';
public function handle() {
$file = $this->argument('file');
$converter = new YamlToPhpConverter();
$services = $converter->convertYamlArray(file_get_contents($file));
// Save to a file or register with Laravel
file_put_contents(storage_path('app/exported_services.php'), var_export($services, true));
$this->info('Services exported!');
}
}
php artisan config:export-s
How can I help you explore Laravel packages today?