Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow symfony 7 #10

Merged
merged 2 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
12 changes: 10 additions & 2 deletions src/Limenius/Liform/Serializer/Normalizer/FormErrorNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,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 +51,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 ['object' => true];
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be more precise.

Suggested change
return ['object' => true];
return [Form:class];

}

/**
* 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 ['object' => 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
Loading