{"id":16864449,"url":"https://github.com/ph-fritsche/liform","last_synced_at":"2025-04-11T09:42:17.349Z","repository":{"id":54321235,"uuid":"261130390","full_name":"ph-fritsche/liform","owner":"ph-fritsche","description":"Transform Symfony Forms into JSON Schema","archived":false,"fork":false,"pushed_at":"2021-07-21T10:00:22.000Z","size":549,"stargazers_count":3,"open_issues_count":2,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-25T06:41:32.539Z","etag":null,"topics":["forms","json-schema","symfony-bundle","symfony-form"],"latest_commit_sha":null,"homepage":"https://ph-fritsche.github.io/liform","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ph-fritsche.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-04T09:23:25.000Z","updated_at":"2023-11-01T07:51:58.000Z","dependencies_parsed_at":"2022-08-13T12:00:37.200Z","dependency_job_id":null,"html_url":"https://github.com/ph-fritsche/liform","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ph-fritsche%2Fliform","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ph-fritsche%2Fliform/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ph-fritsche%2Fliform/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ph-fritsche%2Fliform/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ph-fritsche","download_url":"https://codeload.github.com/ph-fritsche/liform/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248369295,"owners_count":21092550,"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":["forms","json-schema","symfony-bundle","symfony-form"],"created_at":"2024-10-13T14:42:27.018Z","updated_at":"2025-04-11T09:42:17.324Z","avatar_url":"https://github.com/ph-fritsche.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![codecov](https://codecov.io/gh/ph-fritsche/liform/branch/master/graph/badge.svg)](https://codecov.io/gh/ph-fritsche/liform)\n\n# ![Liform](https://ph-fritsche.github.io/liform/assets/liform.png)\n\nLibrary for transforming [Symfony Form Views](https://symfony.com/doc/current/components/form.html) into JSON.\n\nIt is developed to be used with [liform-react-final](https://www.npmjs.com/package/liform-react-final), but can be used with any form rendering supporting [JSON schema](http://json-schema.org/).\n\n## Installation\n\nInstall per [Composer](https://getcomposer.org/) from [Packagist](https://packagist.org/packages/pitch/liform).\n```\ncomposer require pitch/liform\n```\n\nIf you execute this inside a Symfony application with [Symfony Flex](https://symfony.com/doc/current/setup/flex.html),\n`LiformInterface` will be available per [Dependency Injection](https://symfony.com/doc/current/service_container.html#injecting-services-config-into-a-service) right away.\n\n## Basic usage\n\n```php\n$form = \\Symfony\\Component\\Form\\Forms::createFormFactory()-\u003ecreate();\n$form-\u003eadd('foo', \\Symfony\\Component\\Form\\Extension\\Core\\Type\\TextType::class);\n$form-\u003eadd('bar', \\Symfony\\Component\\Form\\Extension\\Core\\Type\\NumberType::class);\n\n/* ... handle the request ... */\n\n$resolver = new \\Pitch\\Liform\\Resolver();\n$resolver-\u003esetTransformer('text', new \\Pitch\\Liform\\Transformer\\StringTransformer());\n$resolver-\u003esetTransformer('number', new \\Pitch\\Liform\\Transformer\\NumberTransformer());\n/* ... */\n\n$liform = new \\Pitch\\Liform\\Liform($resolver);\n$liform-\u003eaddExtension(new \\Pitch\\Liform\\Extension\\ValueExtension());\n$liform-\u003eaddExtension(new \\Pitch\\Liform\\Extension\\LabelExtension());\n/* ... */\n\nreturn $liform-\u003etransform($form-\u003ecreateView());\n```\n\n### Inside a Symfony application\n\n```php\nnamespace App\\Controller;\n\n/* use statements */\n\nclass MyFormController extends Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController\n{\n   protected LiformInterface $liform;\n\n   /* Let the service container inject the service */\n   public function __construct(LiformInterface $liform)\n   {\n      $this-\u003eliform = $liform;\n   }\n\n   public function __invoke(Request $request)\n   {\n      $form = $this-\u003ecreateForm(MyFormType::class);\n      $form-\u003ehandleRequest($request);\n      if ($form-\u003eisSubmitted() \u0026\u0026 $form-\u003eisValid()) {\n         /* ... do something ... */\n      } else {\n         return new Response($this-\u003erender('my_form.html.twig', [\n            'liform' =\u003e $this-\u003eliform-\u003etransform($form-\u003ecreateView()),\n         ]), $form-\u003eisSubmitted() ? 400 : 200);\n      }\n   }\n}\n```\n\n### The result\n\nThe `TransformResult` is an object that when passed through `json_encode()` will produce something like:\n```js\n{\n   \"schema\": {\n      \"title\": \"form\",\n      \"type\": \"object\",\n      \"properties\": {\n         \"foo\": {\n            \"title\": \"foo\",\n            \"type\": \"string\"\n         },\n         \"bar\": {\n            \"title\": \"bar\",\n            \"type\": \"number\",\n         }\n      },\n      \"required\": [\n         \"foo\",\n         \"bar\"\n      ]\n   },\n   \"meta\": {\n      \"errors\": {\n         \"foo\": [\"This is required.\"]\n      }\n   },\n   \"values\": {\n      \"bar\": 42\n   }\n}\n```\n\n## Acknowledgements\n\nThis library is based on [Limenius/Liform](https://github.com/Limenius/Liform).\nIts technique for transforming forms using resolvers and reducers is inspired by [Symfony Console Form](https://github.com/matthiasnoback/symfony-console-form).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fph-fritsche%2Fliform","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fph-fritsche%2Fliform","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fph-fritsche%2Fliform/lists"}