Skip to content

Commit

Permalink
Imported code from LiformBundle
Browse files Browse the repository at this point in the history
  • Loading branch information
nacmartin committed Jan 29, 2017
0 parents commit ba6e7df
Show file tree
Hide file tree
Showing 21 changed files with 1,415 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/vendor/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Nacho Martín

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
95 changes: 95 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
Liform
======

Library to serialize Symfony Forms into [JSON schema](http://json-schema.org/). For use with [liform-react](https://github.com/Limenius/liform-react) or [json-editor](https://github.com/jdorn/json-editor), or any other form generator based in json-schema.

It is used by [LiformBundle](https://github.com/Limenius/LiformBundle) but can be used stand-alone.

It is very annoying to maintain backend forms that match forms in a client technology, such as JavaScript. It is also annoying to maintain a documentation of such forms. And error prone.

LiformBundle generates a JSON schema representation, that serves as documentation and can be used to document, validate your data and, if you want, to generate forms using a generator.

## Installation

Open a command console, enter your project directory and execute the
following command to download the latest stable version of this library:

$ composer require limenius/liform

This command requires you to have Composer installed globally, as explained
in the *installation chapter* of the Composer documentation.

> Liform follows the PSR-4 convention names for its classes, which means you can easily integrate `Liform` classes loading in your own autoloader.

## Usage

Serializing a form into JSON Schema:

```php
$form = $this->createForm(CarType::class, $car, ['csrf_protection' => false]);
$schema = json_encode($liform->transform($form));
```

And `$schema` will contain a JSON Schema representation such as:

```js
{
"title":null,
"properties":{
"name":{
"type":"string",
"title":"Name",
"propertyOrder":1
},
"color":{
"type":"string",
"title":"Color",
"attr":{
"placeholder":"444444"
},
"default":"444444",
"description":"3 hexadecimal digits",
"propertyOrder":2
},
"drivers":{
"type":"array",
"title":"hola",
"items":{
"title":"Drivers",
"properties":{
"firstName":{
"type":"string",
"propertyOrder":1
},
"familyName":{
"type":"string",
"propertyOrder":2
}
},
"required":[
"firstName",
"familyName"
],
"type":"object"
},
"propertyOrder":3
}
},
"required":[
"name",
"drivers"
]
}

```

## License

This library is under the MIT license. See the complete license in the file:

LICENSE.md

## Acknoledgements

The technique for transforming forms using resolvers and reducers is inspired on [Symfony Console Form](https://github.com/matthiasnoback/symfony-console-form)
18 changes: 18 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "limenius/liform",
"description": "Library to transform Symfony Forms into Json Schema",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Nacho Martín",
"email": "nacho@limenius.com"
}
],
"autoload": {
"psr-4": { "Limenius\\Liform\\": "src" }
},
"require": {
"symfony/form": "~2.3|~3.0"
}
}
Loading

0 comments on commit ba6e7df

Please sign in to comment.