PHPackages                             basster/lazy-response-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. basster/lazy-response-bundle

ActiveLibrary[Framework](/categories/framework)

basster/lazy-response-bundle
============================

A library to support so-called lazy symfony controller responses.

2.0(5y ago)014.7k↓50%1MITPHPPHP &gt;=8.0

Since Jul 28Pushed 5y ago2 watchersCompare

[ Source](https://github.com/Basster/lazy-response-bundle)[ Packagist](https://packagist.org/packages/basster/lazy-response-bundle)[ RSS](/packages/basster-lazy-response-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (11)Versions (6)Used By (0)

Lazy Response Bundle
====================

[](#lazy-response-bundle)

[![Build Status](https://camo.githubusercontent.com/4f78dfaafc9ce2bd60f4b967c51bde934a891161ae312983aa1e7d71121e0394/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f426173737465722f6c617a792d726573706f6e73652d62756e646c652f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Basster/lazy-response-bundle/build-status/master) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/700dcfd9afae2a421f67dcbc7cbad618036bcfde4f850e3b6db450e564ed0a04/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f426173737465722f6c617a792d726573706f6e73652d62756e646c652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Basster/lazy-response-bundle/?branch=master) [![Code Coverage](https://camo.githubusercontent.com/0eff6c50b05d4f217f13f47f60d8caba5f8f4267ae122b6ea8f867bfd3d4f9ed/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f426173737465722f6c617a792d726573706f6e73652d62756e646c652f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Basster/lazy-response-bundle/?branch=master)

I prefer to handle response type outside of Symfony controllers and return DTOs instead which are transformed into their corresponding responses afterwards. Some of the very standard DTOs and `kernel.view` event handlers are in this library.

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

[](#installation)

```
composer req basster/lazy-response-bundle
```

If you are using [Symfony Flex](https://flex.symfony.com/) you are done here, otherwise add the following lines to your `services.yaml`:

```
services:
    _defaults:
        # make sure autowire and autoconfigure are activated
        autowire: true
        autoconfigure: true

    Basster\LazyResponseBundle\Response\Handler\TwigResponseHandler: ~
    Basster\LazyResponseBundle\Response\Handler\RedirectResponseHandler: ~
    Basster\LazyResponseBundle\Response\Handler\JsonSerializeResponseHandler: ~
```

Usage
-----

[](#usage)

I prefer pure Symfony controllers without extending the `Symfony\Bundle\FrameworkBundle\Controller\AbstractController`, using proper Dependency Injection to get the services I want to use. I also liked the idea of the `@Template` annotation, so controllers return data, no responses. But sometimes, that comes with a drawback: If you want to attach proper typehints to your controller actions. E.g. if you handle a form in an action, you return either view model as array or a `RedirectResponse` after successful form handling. Downside: Those "return types" have nothing in common.

Here is my approach:

```
