PHP code example of symplify / php-config-printer

1. Go to this page and download the library: Download symplify/php-config-printer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

symplify / php-config-printer example snippets


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
        // ...
    }
}