Skip to content

Commit

Permalink
Merge pull request #1 from survos/tac
Browse files Browse the repository at this point in the history
Tac
  • Loading branch information
lsv authored Jan 5, 2024
2 parents 7f2b90d + e5d81c9 commit e0d665e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ in the *installation chapter* of the Composer documentation.
#### Note
`symfony/form ^5.0` broke backwards compatibility on some abstract functions we use. If you need to function with
earlier versions, you need to use Liform v0.15 or earlier:

$ composer require limenius/liform "^0.15"
```bash
composer require limenius/liform "^0.15"
```

## Usage

Expand All @@ -54,7 +55,7 @@ $schema = json_encode($liform->transform($form));

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

```js
```json
{
"title":null,
"properties":{
Expand Down Expand Up @@ -354,6 +355,6 @@ This library is under the MIT license. See the complete license in the file:

LICENSE.md

## Acknoledgements
## Acknowledgements

The technique for transforming forms using resolvers and reducers is inspired on [Symfony Console Form](https://github.com/matthiasnoback/symfony-console-form)
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
}
},
"require": {
"php": "^7.4|^8.0",
"symfony/form": "^5.4|^6.0",
"symfony/translation": "^5.4|^6.0",
"symfony/serializer": "^5.4|^6.0",
"symfony/validator": "^5.4|^6.0",
"php": "^8.0",
"symfony/form": "^5.4|^6.3|^7.0",
"symfony/translation": "^5.4|^6.3|^7.0",
"symfony/serializer": "^5.4|^6.3|^7.0",
"symfony/validator": "^5.4|^6.3|^7.0",
"symfony/translation-contracts": "^1.0|^2.1|^3.0"
},
"require-dev": {
Expand Down
2 changes: 1 addition & 1 deletion src/Limenius/Liform/Form/Extension/AddLiformExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static function getExtendedTypes(): iterable
*
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefined(['liform']);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class InitialValuesNormalizer implements NormalizerInterface
/**
* {@inheritdoc}
*/
public function normalize($form, $format = null, array $context = [])
public function normalize($form, $format = null, array $context = []): float|array|\ArrayObject|bool|int|string|null
{
$formView = $form->createView();

Expand All @@ -35,8 +35,11 @@ public function normalize($form, $format = null, array $context = [])

/**
* {@inheritdoc}
* @param mixed $data
* @param null $format
* @param array $context
*/
public function supportsNormalization($data, $format = null)
public function supportsNormalization($data, $format = null, array $context = []): bool
{
return $data instanceof Form;
}
Expand All @@ -48,7 +51,7 @@ public function supportsNormalization($data, $format = null)
*
* @return mixed
*/
private function getValues(Form $form, FormView $formView)
private function getValues(Form $form, FormView $formView): mixed
{
if (!empty($formView->children)) {
if (in_array('choice', FormUtil::typeAncestry($form)) &&
Expand Down Expand Up @@ -88,7 +91,7 @@ private function getValues(Form $form, FormView $formView)
*
* @return array
*/
private function normalizeMultipleExpandedChoice(FormView $formView)
private function normalizeMultipleExpandedChoice(FormView $formView): array
{
$data = array();
foreach ($formView->children as $name => $child) {
Expand All @@ -106,7 +109,7 @@ private function normalizeMultipleExpandedChoice(FormView $formView)
*
* @return mixed
*/
private function normalizeExpandedChoice(FormView $formView)
private function normalizeExpandedChoice(FormView $formView): mixed
{
foreach ($formView->children as $name => $child) {
if ($child->vars['checked']) {
Expand All @@ -116,4 +119,9 @@ private function normalizeExpandedChoice(FormView $formView)

return null;
}

public function getSupportedTypes(?string $format): array
{
return [Form::class];
}
}

0 comments on commit e0d665e

Please sign in to comment.