Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/solidworx/simpleresponsebundle

Convert simple classes to Symfony response objects
https://github.com/solidworx/simpleresponsebundle

response symfony symfony-bundle symfony3 symfony4 utility-library

Last synced: about 1 month ago
JSON representation

Convert simple classes to Symfony response objects

Awesome Lists containing this project

README

        

Simple Response Bundle
======================

SimpleResponseBundle is a bundle for the Symfony framework which allows you to return customised response classes in your controllers/actions which reduces the amount of dependencies you controller or action needs.

Installation
------------

To install the bundle using composer, run the following command:

```bash
$ composer require solidworx/simple-response-handler
```

After you have installed the bundle, then you need to register the bundle in your application

```php
entity = $entity;
parent::__construct();
}

public function getEntity(): string
{
return $this->entity;
}
}
```

Your handler class will add the logic to return a response object;

```php
em = $entityManager;
}

public function supports(Response $object): bool
{
return $object instanceof DoctrineEntityReponse; // Only support responses of this type
}

public function handle(Response $object): Response
{
return $object->setData($this->em->getRepository($object->getEntity())->findAll()); // Return all records in the entity as a JSON response
}
}
```

Then you can use your new class in your action:

```php