{"id":15287251,"url":"https://github.com/basster/lazy-response-bundle","last_synced_at":"2025-03-24T02:48:19.880Z","repository":{"id":54251022,"uuid":"199145439","full_name":"Basster/lazy-response-bundle","owner":"Basster","description":"Symfony components to support, what I call \"lazy responses\"","archived":false,"fork":false,"pushed_at":"2021-03-01T16:06:39.000Z","size":27,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T02:48:15.731Z","etag":null,"topics":["php","symfony"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Basster.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-27T09:40:13.000Z","updated_at":"2021-03-01T16:05:54.000Z","dependencies_parsed_at":"2022-08-13T10:01:02.049Z","dependency_job_id":null,"html_url":"https://github.com/Basster/lazy-response-bundle","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Basster%2Flazy-response-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Basster%2Flazy-response-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Basster%2Flazy-response-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Basster%2Flazy-response-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Basster","download_url":"https://codeload.github.com/Basster/lazy-response-bundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245200679,"owners_count":20576673,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["php","symfony"],"created_at":"2024-09-30T15:27:07.072Z","updated_at":"2025-03-24T02:48:19.861Z","avatar_url":"https://github.com/Basster.png","language":"PHP","readme":"Lazy Response Bundle\n=====================\n\n[![Build Status](https://scrutinizer-ci.com/g/Basster/lazy-response-bundle/badges/build.png?b=master)](https://scrutinizer-ci.com/g/Basster/lazy-response-bundle/build-status/master) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Basster/lazy-response-bundle/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Basster/lazy-response-bundle/?branch=master) [![Code Coverage](https://scrutinizer-ci.com/g/Basster/lazy-response-bundle/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/Basster/lazy-response-bundle/?branch=master) \n\nI 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.\n\nInstallation\n-------------\n\n```bash\ncomposer req basster/lazy-response-bundle\n```\n\nIf you are using [Symfony Flex](https://flex.symfony.com/) you are done here, otherwise add the following lines to your `services.yaml`:\n\n```yaml\nservices:\n    _defaults:\n        # make sure autowire and autoconfigure are activated\n        autowire: true      \n        autoconfigure: true\n    \n    Basster\\LazyResponseBundle\\Response\\Handler\\TwigResponseHandler: ~\n    Basster\\LazyResponseBundle\\Response\\Handler\\RedirectResponseHandler: ~\n    Basster\\LazyResponseBundle\\Response\\Handler\\JsonSerializeResponseHandler: ~\n```\n\nUsage\n-----\n\nI 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.\n\nHere is my approach:\n\n```php\n\u003c?php \nuse Basster\\LazyResponseBundle\\Response\\LazyResponseInterface;\nuse Basster\\LazyResponseBundle\\Response\\RedirectResponse;\nuse Basster\\LazyResponseBundle\\Response\\TemplateResponse;\n\nclass MyController {\n    public function commentNew(Request $request, FormFactoryInterface $formFactory): LazyResponseInterface\n    {\n        $post = new Post();\n    \n        $form = $formFactory-\u003ecreate(PostType::class, $post);\n        $form-\u003ehandleRequest($request);\n    \n        if ($form-\u003eisSubmitted() \u0026\u0026 $form-\u003eisValid()) {\n            // do stuff with the submitted data\n            return new RedirectResponse('post_index'); // will end up in a RedirectResponse\n        }\n        \n        return new TemplateResponse('post/new.html.twig',[\n            'post' =\u003e $post,\n            'form' =\u003e $form-\u003ecreateView(),\n        ]); // will end up in a regular Response with contents of the rendered template.\n    }\n}\n```\n\nLazyResponseInterface\n---------------------\n\nThe `Basster\\LazyResponseBundle\\Response\\LazyResponseInterface` is just a marking interface to be shared by multiple DTOs. Currently there are the following standard DTOs:\n\n* `Basster\\LazyResponseBundle\\Response\\JsonSerializeResponse`\n* `Basster\\LazyResponseBundle\\Response\\RedirectResponse`\n* `Basster\\LazyResponseBundle\\Response\\TemplateResponse`\n\nThe response DTOs are framework agnostic and can be used wherever you want!\n\nLazyResponseHandlers\n--------------------\n\nThe handlers, that come with this library, are Symfony `kernel.view` event subscriber transforming the DTOs into Symfony response objects:\n\n* `Basster\\LazyResponseBundle\\Response\\Handler\\JsonSerializeResponseHandler` handles `JsonSerializeResponse` and utilizes the Symfony serializer.\n* `Basster\\LazyResponseBundle\\Response\\Handler\\RedirectResponseHandler` handles `RedirectResponse` and utilizes the Symfony router.\n* `Basster\\LazyResponseBundle\\Response\\Handler\\TwigResponseHandler` handles `TemplateResponse` utilizes Twig (doh!). \n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbasster%2Flazy-response-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbasster%2Flazy-response-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbasster%2Flazy-response-bundle/lists"}