gheb/configuration-converter-bundle

Convert your API Platform configuration from a format to another

0.5.2 2019-04-07 07:44 UTC

README

CircleCI Coverage Status

Do not worry about you configuration at first. When you start working on your project, the documentation (and because it's easy to make a POC with) show you how to configure your resources with annotations. And it's usually a good practice in some cases to use annotations. But when your project is growing, you start to realize that you need to change for a more suitable, maintainable format like XML or YAML. It's time consuming, not painless, and not error free.

I've written this bundle for this occasion.

Note: Always double check you new configuration for edge cases that might not be covered. And please report it here so every case can fill in the gap.

Installation

$ composer require --dev gheb/configuration-converter-bundle

Register the bundle.

For symfony < 3.4

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = [
        // ...
    ];

    if (in_array($this->getEnvironment(), ['dev'])) {
        //...
        $bundles[] = new ConfigurationConverter\ConfigurationConverterBundle();
    }

    return $bundles;
}

For symfony > 4

<?php
// config/bundles.php

<?php

return [
    // ...
    ConfigurationConverter\ConfigurationConverterBundle::class => ['dev' => true],
];

Configuration

Configure the bundle to your needs, for example:

# config/packages/configuration_converter.yaml
configuration_converter:
    api_platform_default_export_dir: '%kernel.project_dir%/config/packages/api-platform/' #(default)

Usage

The most classic use case is when you started to follow the documentation originally written with annotation. By default we recommend the 'XML' configuration format.

To convert every single one of your entities configuration in xml.

$ php bin/console configuration:convert

To convert a specific entity configuration in xml.

$ php bin/console configuration:convert -r 'FQCN\Of\Your\Entity'

To use another format, use --format|-f option.

$ php bin/console configuration:convert -r 'FQCN\Of\Your\Entity' -f 'xml'
$ php bin/console configuration:convert -r 'FQCN\Of\Your\Entity' -f 'yml'

By default, you'll need to copy and paste the configuration from the CLI output, but you can export the format to a specific directory. Use --output|-o option. By default it will export to config/packages/api-platform directory.

$ php bin/console configuration:convert -r 'FQCN\Of\Your\Entity' -o
$ php bin/console configuration:convert -r 'FQCN\Of\Your\Entity' -o 'custom/repository'

Contributing

Fork the project, create a branch according to your contribution, code and follow the contributing.md.

Here is the way I see the next versions, any help is welcome :)

  • Add YAML support
  • Add serialization groups conversion
  • Add assertion conversion
  • Add doctrine conversion