Skip to content

Commit

Permalink
Allow symfony 7 (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
ropczan authored Jun 14, 2024
1 parent 445ccba commit 544d835
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 19 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ jobs:
strategy:
matrix:
php-version:
- "7.4"
- "8.0"
- "8.1"
- "8.2"
deps:
- "normal"
include:
- deps: "low"
php-version: "7.4"
php-version: "8.0"

steps:
- name: "Checkout"
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ jobs:
strategy:
matrix:
php-version:
- "7.4"
- "8.0"
- "8.1"
steps:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
composer.lock
coverage/
.phpunit.result.cache
.idea/
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": "^6.0|^7.0",
"symfony/translation": "^6.0|^7.0",
"symfony/serializer": "^6.0|^7.0",
"symfony/validator": "^6.0|^7.0"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^v0.7.2",
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
13 changes: 11 additions & 2 deletions src/Limenius/Liform/Serializer/Normalizer/FormErrorNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Limenius\Liform\Serializer\Normalizer;

use Symfony\Component\Form\Form;
use Symfony\Component\Form\FormError;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
Expand Down Expand Up @@ -39,7 +40,7 @@ public function __construct(TranslatorInterface $translator)
/**
* {@inheritdoc}
*/
public function normalize($object, $format = null, array $context = [])
public function normalize(mixed $object, ?string $format = null, array $context = []): float|array|\ArrayObject|bool|int|string|null
{
return [
'code' => isset($context['status_code']) ? $context['status_code'] : null,
Expand All @@ -51,11 +52,19 @@ public function normalize($object, $format = null, array $context = [])
/**
* {@inheritdoc}
*/
public function supportsNormalization($data, $format = null)
public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
{
return $data instanceof FormInterface && $data->isSubmitted() && !$data->isValid();
}

/**
* {@inheritdoc}
*/
public function getSupportedTypes(?string $format): array
{
return [Form::class => true];
}

/**
* This code has been taken from JMSSerializer.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,34 @@ class InitialValuesNormalizer implements NormalizerInterface
/**
* {@inheritdoc}
*/
public function normalize($form, $format = null, array $context = [])
public function normalize($object, $format = null, array $context = []): float|array|\ArrayObject|bool|int|string|null
{
$formView = $form->createView();
$formView = $object->createView();

return $this->getValues($form, $formView);
return $this->getValues($object, $formView);
}

/**
* {@inheritdoc}
*/
public function supportsNormalization($data, $format = null)
public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
{
return $data instanceof Form;
}

/**
* {@inheritdoc}
*/
public function getSupportedTypes(?string $format): array
{
return [Form::class => true];
}

/**
* Gets the values of the form
* @param Form|FormInterface $form
* @param FormView $formView
*
* @param Form|FormInterface $form
* @param FormView $formView
*
* @return mixed
*/
Expand All @@ -62,7 +71,7 @@ private function getValues(FormInterface $form, FormView $formView)
return $this->normalizeExpandedChoice($formView);
}
// Force serialization as {} instead of []
$data = (object) array();
$data = (object) [];
foreach ($formView->children as $name => $child) {
// Avoid unknown field error when csrf_protection is true
// CSRF token should be extracted another way
Expand All @@ -85,13 +94,14 @@ private function getValues(FormInterface $form, FormView $formView)

/**
* Normalize when choice is multiple
*
* @param FormView $formView
*
* @return array
*/
private function normalizeMultipleExpandedChoice(FormView $formView)
{
$data = array();
$data = [];
foreach ($formView->children as $name => $child) {
if ($child->vars['checked']) {
$data[] = $child->vars['value'];
Expand All @@ -103,6 +113,7 @@ private function normalizeMultipleExpandedChoice(FormView $formView)

/**
* Normalize when choice is expanded
*
* @param FormView $formView
*
* @return mixed
Expand Down

0 comments on commit 544d835

Please sign in to comment.