Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/solidworx/simpleresponsebundle
- Owner: SolidWorx
- License: mit
- Created: 2018-03-11T19:59:15.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-03-03T07:16:47.000Z (over 4 years ago)
- Last Synced: 2024-10-13T06:22:16.655Z (about 1 month ago)
- Topics: response, symfony, symfony-bundle, symfony3, symfony4, utility-library
- Language: PHP
- Size: 15.6 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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