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.
[!WARNING] This package is deprecated and no longer maintained.
It has been merged into symplify/config-transformer, where it now lives under
packages/php-config-printer.Please use
symplify/config-transformerinstead:composer require symplify/config-transformer --devThe
Symplify\PhpConfigPrinter\namespace and its classes are unchanged.
Print Symfony services array with configuration to to plain PHP file format using nikic/php-parser
composer require symplify/php-config-printer --dev
Register config in your services:
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\PhpConfigPrinter\ValueObject\PhpConfigPrinterConfig;
return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->import(PhpConfigPrinterConfig::FILE_PATH);
};
use Symplify\PhpConfigPrinter\Printer\SmartPhpConfigPrinter;
/** @var SmartPhpConfigPrinter $smartConfigPrinter */
$config = [
'SomeService' => [
'key' => 'value',
],
];
$smartConfigPrinter->printConfiguredServices($config);
use Symplify\ConfigTransformer\Converter\YamlToPhpConverter;
class SomeClass
{
/**
* @var YamlToPhpConverter
*/
private $yamlToPhpConverter;
public function __construct(YamlToPhpConverter $yamlToPhpConverter)
{
$this->yamlToPhpConverter = $yamlToPhpConverter;
}
public function run(): void
{
$phpFileContent = $this->yamlToPhpConverter->convertYamlArray([
'parameters' => [
'key' => 'value',
],
'services' => [
'_defaults' => [
'autowire' => true,
'autoconfigure' => true,
],
],
]);
// dump the $phpFileContent file
// ...
}
}
How can I help you explore Laravel packages today?