Converting DI config files to Disco configuration

Converting DI config files to Disco configuration

Given you want to introduce Disco into a legacy project, you need to manually convert the existing DI configuration into Disco's class based configuration format. This requires you to have in-depth knowledge about the DI container format your project is using right now as well as some in-depth knowledge of Disco's configuration. Some examples to give you guidance for the conversion process can be found online in the disco-demos repository. But there is more, Andreas Heigl created a CLI tool called manero to help you to automatically convert existing DI configuration into Disco's class based configuration format. In the first step, manero is only able to convert Zend Expressive configurations. The current conversion process looks like this: First you need to clone the repo and create a .phar file of manero yourself:

git clone https://github.com/tonymanero/manero.git
cd manero
./createPhar.sh


This will create a file called manero.phar in the build/build directory. Copy the manero.phar file to your Expressive application and edit the config/container.php file adding the following line before the return statement:

file_put_contents(getcwd() . '/config.json', json_encode($config));


Run the application once so that the config.json file is created, manero is using this file to create the Disco configuration. The conversion process is started by calling manero.phar like this from the root folder of your application:

php manero.phar convert:zend-expressive config.json


This will create a new file called ManeroConfigTrait.php which you can put alongside the Disco configuration. Simply include the trait in your main configuration class - before that you might need to change the namespace of the generated file.

In case you want manero to handle the DI configuration for your DI container of choice, let Andreas know by opening an issue on Github.

In case you are wondering about the name, Tony Manero is the main character from the film Saturday Night Fever. What a perfect name for such a tool ;)


Eintrag von Stephan Hochdörfer am 22.03.2018

Tags: PHP, Disco, Manero

Diese Webseite verwendet Cookies, um die Bedienfreundlichkeit zu erhöhen. Mit der Nutzung unserer Webseite wird das Einverständnis erklärt, dass wir Cookies verwenden. Weitere Informationen.