it-bens/api-platform-utilites-bundle

v0.1.1 2021-10-13 07:13 UTC

This package is auto-updated.

Last update: 2024-04-13 13:25:45 UTC


README

Maintenance Status Build Status Coverage Status

This bundle provides a set of useful abstract classes that encapsulate some logic for the usage of API platform. Furthermore, it implements an easily configurable input- and output transformer system that can be used without further classes.

How to install the bundle?

The bundle can be installed via Composer:

composer require it-bens/api-platform-utilites-bundle

If you're using Symfony Flex, the bundle will be automatically enabled. For older apps, enable it in your Kernel class.

⚠ The ITB\ObjectTransformerBundle should be enabled, too.

What does this bundle provide and how to use it?

Let's start with the non-configurable stuff.

DataProvider

DataPersister

DataTransformer

Now we'll take a look at the DataTransformer system, that this bundle provides (or extends).

The typical use-case for the API Platform data transformer system is to transform DTOs to Entities/Objects and vice versa. This bundle uses the TransformationMediator from the Object Transformer Bundle.

Normally, you would probably write an implementation of the API Platform DataTransformerInterface for every DTO transformation that should be performed during the ordinary data flow, described here. That's quite a mess if there are a lot of resources, requests DTOs and response DTOs. The ApiInputTransformer and ApiOutputTransformer classes handle that complete process with a tiny bit of configuration.

After the bundle is enabled, a itb_api_platform_utilities.yaml file should be created. Every transformation the two transformers should handle, has to be registered here. Here's an example:

itb_api_platform_utilities:
  input_transformations:
    - { request_class: 'ITB\ObjectTransformerTestUtilities\Object1', object_class: 'ITB\ObjectTransformerTestUtilities\Object2' }
  output_transformations:
    - { object_class: 'ITB\ObjectTransformerTestUtilities\Object2', response_class: 'ITB\ObjectTransformerTestUtilities\Object1' }

Every line represents a registered transformation. The configuration is allowed to be empty, which means that the transformers of this bundle won't be used. Otherwise, all the keys you see are required and the have to present fully qualified class names.

⚠ The transformers will use the TransformationMediator as described. That means there should be transformers, that can handle the registered transformations.

That's all you have to configure or implement.

What else?

For the configuration and usage of Object Transformer bundle see:

Contributing

I am really happy that the software developer community loves Open Source, like I do! ♥

That's why I appreciate every issue that is opened (preferably constructive) and every pull request that provides other or even better code to this package.

You are all breathtaking!