Introducing Neon to YAML Converter

Found a typo? Edit me
This post is deprecated since June 2021. Its knowledge is old and should not be used.
Why?

This package got only couple of downloads (2 exactly :)) in last years. That's why I decide to deprecate it. If you still need it, you can find it here.


This post was updated at July 2020 with fresh know-how.
What is new?

Updated to Symplify package.


I wrote about How to migrate between Neon to Yaml almost a year ago. Recently we needed to migrate many files with parameters, imports, and mainly services.

Neon and YAML are basically arrays, right? So why not let a tool let do the dirty work?

When Do You need it?

How to Use it?

To use symplify/neon-to-yaml-converter, require it a composer dependency:

composer require symplify/neon-to-yaml-converter --dev

Run it on one file or directory - it takes all *.neon, *.yml and *.yaml files:

vendor/bin/neon-to-yaml-converter convert file.neon

The 2 Most Problematic Places Converter Tool Handles

In Neon there are nested parameters = you can use %payu.user% to get parameter user in payu array. In YAML used in Symfony code, there are only one level parameters. That means you can use only the payu parameter, nothing nested.

That's why all parameters have to be converted to the single level of nesting, here to payu_user:

 parameters:
-    payu:
-       user: Pepa
+    payu_user: Pepa
-       password: abz123
+    payu_password: abz123

 services:
     PayuService:
         arguments:
-            - '%payu.user%'
+            - '%payu_user%'
-            - '%payu.password%'
+            - '%payu_password%'

Another case are Neon entities. Their goal is to make syntax short. Its cost is less readability.

Code is actually parsed to an object, that has different meaning in different places:

 services:
-    - App\SomeService(@anotherService, %perex%)
+    App\SomeService:
+        arguments:
+            - @anotherService
+            - %perex%

Those of you who don't use Neon for years, would you guess that?

All this converter handles for you.


Next time you migrate your config, package or whole application from Neon to YAML, let symplify/neon-to-yaml-conveter do the work for you.


Happy coding!


Have you find this post useful? Do you want more?

Follow me on Twitter, RSS or support me on GitHub Sponsors.