migrify/php-config-printer

Print Symfony services array with configuration to to plain PHP file format thanks to this simple php-parser wrapper

0.3.51 2020-10-25 12:24 UTC

README

Downloads total

Print Symfony services array with configuration to to plain PHP file format thanks to this simple php-parser wrapper

Install

composer require migrify/php-config-printer --dev

Register bundle in your Kernel:

namespace App;

use Migrify\PhpConfigPrinter\Bundle\PhpConfigPrinterBundle;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;

final class AppKernel
{
    /**
     * @return BundleInterface[]
     */
    public function registerBundles(): array
    {
        return [new PhpConfigPrinterBundle()];
    }
}

Use

1. Only Configured Services

<?php

/** @var \Migrify\PhpConfigPrinter\Printer\SmartPhpConfigPrinter $smartConfigPrinter */
$config = [
    'SomeService' => [
        'key' => 'value'
    ]
];

$smartConfigPrinter->printConfiguredServices($config);

2. Full Config

<?php

use Migrify\PhpConfigPrinter\YamlToPhpConverter;

class SomeClass
{
    /**
     * @var YamlToPhpConverter
     */
    private $yamlToPhpConverter;
    
    public function __construct(YamlToPhpConverter $yamlToPhpConverter)
    {
        $this->yamlToPhpConverter = $yamlToPhpConverter;
    }
    
    public function run()
    {
        $phpFileContent = $this->yamlToPhpConverter->convertYamlArray([
            'parameters' => [
                'key' => 'value',
            ],
            'services' => [
                '_defaults' => [
                    'autowire' => true,
                    'autoconfigure' => true,
                ]       
            ]       
        ]);

        // dump the $phpFileContent file
        // ... 
    }
}