SkillAgentSearch skills...

DataTransformationBundle

Transforming to or from JSON for Symfony2 REST-Controller

Install / Use

/learn @RtxLabs/DataTransformationBundle
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

DataTransformation Bundle

Symfony2 Bundle that can help building REST services.

Build Status

Example

Providing a REST service that returns a list of contacts linked with companies. The service has to deliver something like that:

[{
    "id": 1181,
    "address": null,
    "email": "max.mustermann@dtb.com",
    "firstname": "Max",
    "lastname": "Mustermann",
    "company": 7
} , {
    "id" : 1177,
    "address" : null,
    "email" : "uwe.klawitter@dtb.com",
    "firstname" : "Uwe",
    "lastname" : "Klawitter",
    "company": 298
}]

To generate this, some Doctrine entities have to be loaded from a repository and converted into json. Performing an json_encode() to on the entities won't work, because the entity contains proxy objects to the company. To solve this, the DoctrineBinder can be used:

$result = $this->container->get('doctrinebinder')->bind($models)->execute();

// finally the result has to be converted into json to return it as an response
$json = Dencoder::decode($result);

Documentation

View on GitHub
GitHub Stars13
CategoryDevelopment
Updated3y ago
Forks1

Languages

PHP

Security Score

60/100

Audited on Nov 20, 2022

No findings