Merged
Conversation
f7dd6e0 to
3f6c15b
Compare
ad1fd28 to
efd423d
Compare
Fluid allows ViewHelpers to specify their API by using `AbstractViewHelper::registerArgument()`, which is usually called in `initializeArguments()` of the ViewHelper. Internally, `ArgumentDefinition` is used to represent the provided argument information and constraints. Among those is the ability to specify the type of an argument as well as if the argument should be a required argument. While the required status is already validated at the parser level, the argument types are validated by the ViewHelper implementation. However, in most cases, Fluid's built-in validation method by `AbstractViewHelper` is used. Unfortunately, this implementation has many flaws: * it only covers a subset of possible types (e. g. it covers "boolean", but not "bool") * It doesn't ensure the correct argument type for scalar arguments (e. g. you might receive an integer in your ViewHelper implementation, even if the argument has been defined as "string") * There are several small inconsistencies In order to fix this in a future Fluid version without introducing too many hard-to-debug breaking changes, a new API is introduced which extracts validation functionality from the `AbstractViewHelper` and allows alternative implementations in the future. It also adds the possibility to pre-process arguments before their validity is checked, which will allow implicit type conversions in the future (e. g. convert "int" to "string"). As a first step, the existing helper methods `isValidType()` and `getFirstElementOfNonEmpty()` are deprecated and extracted into a `LenientArgumentProcessor`, which mimicks the current validation behavior. Like the current implementation, it doesn't modify the argument types, but rather passes them along unmodified. The new API is then called for the pre-processing step in `ViewHelperInvoker` as well as the validation step in `AbstractViewHelper`. In this first implementation, it isn't possible yet to replace the default implementation with an alternative.
efd423d to
18800e9
Compare
lolli42
approved these changes
May 6, 2025
sbuerk
approved these changes
May 6, 2025
s2b
added a commit
that referenced
this pull request
Aug 15, 2025
Fluid v4.2.0 introduced a new API to process component and ViewHelper arguments (see #1062). To avoid breaking changes in Fluid v4 with how ViewHelpers handle their arguments, a `LenientArgumentProcessor` has been introduced which has been used exclusively for ViewHelpers. Components have used the new `StrictArgumentProcessor` from the beginning. With this breaking change, this is now unified: `StrictArgumentProcessor` is now used for ViewHelper arguments as well. This allows us to define an API in a follow-up patch that allows developers to define their custom argument processing and validation logic or extend/wrap the existing logic by Fluid. The `StrictArgumentProcessor` deals with argument types in a stricter way: If the supplied argument value doesn't meet the type requirement, an exception is thrown. For scalar types, automatic type conversion is happening in a processing step to avoid errors that can be easily solved by Fluid itself (like "string is required, integer given"). There might be consequences for custom ViewHelpers, however in most cases this change will make a lot of custom validation code that was necessary until Fluid v5 obsolete.
s2b
added a commit
that referenced
this pull request
Aug 15, 2025
Fluid v4.2.0 introduced a new API to process component and ViewHelper arguments (see #1062). To avoid breaking changes in Fluid v4 with how ViewHelpers handle their arguments, a `LenientArgumentProcessor` has been introduced which has been used exclusively for ViewHelpers. Components have used the new `StrictArgumentProcessor` from the beginning. With this breaking change, this is now unified: `StrictArgumentProcessor` is now used for ViewHelper arguments as well. This allows us to define an API in a follow-up patch that allows developers to define their custom argument processing and validation logic or extend/wrap the existing logic by Fluid. The `StrictArgumentProcessor` deals with argument types in a stricter way: If the supplied argument value doesn't meet the type requirement, an exception is thrown. For scalar types, automatic type conversion is happening in a processing step to avoid errors that can be easily solved by Fluid itself (like "string is required, integer given"). There might be consequences for custom ViewHelpers, however in most cases this change will make a lot of custom validation code that was necessary until Fluid v5 obsolete.
s2b
added a commit
that referenced
this pull request
Aug 15, 2025
Fluid v4.2.0 introduced a new API to process component and ViewHelper arguments (see #1062). To avoid breaking changes in Fluid v4 with how ViewHelpers handle their arguments, a `LenientArgumentProcessor` has been introduced which has been used exclusively for ViewHelpers. Components have used the new `StrictArgumentProcessor` from the beginning. With this breaking change, this is now unified: `StrictArgumentProcessor` is now used for ViewHelper arguments as well. This allows us to define an API in a follow-up patch that allows developers to define their custom argument processing and validation logic or extend/wrap the existing logic by Fluid. The `StrictArgumentProcessor` deals with argument types in a stricter way: If the supplied argument value doesn't meet the type requirement, an exception is thrown. For scalar types, automatic type conversion is happening in a processing step to avoid errors that can be easily solved by Fluid itself (like "string is required, integer given"). There might be consequences for custom ViewHelpers, however in most cases this change will make a lot of custom validation code that was necessary until Fluid v5 obsolete.
s2b
added a commit
that referenced
this pull request
Aug 15, 2025
Fluid v4.2.0 introduced a new API to process component and ViewHelper arguments (see #1062). To avoid breaking changes in Fluid v4 with how ViewHelpers handle their arguments, a `LenientArgumentProcessor` has been introduced which has been used exclusively for ViewHelpers. Components have used the new `StrictArgumentProcessor` from the beginning. With this breaking change, this is now unified: `StrictArgumentProcessor` is now used for ViewHelper arguments as well. This allows us to define an API in a follow-up patch that allows developers to define their custom argument processing and validation logic or extend/wrap the existing logic by Fluid. The `StrictArgumentProcessor` deals with argument types in a stricter way: If the supplied argument value doesn't meet the type requirement, an exception is thrown. For scalar types, automatic type conversion is happening in a processing step to avoid errors that can be easily solved by Fluid itself (like "string is required, integer given"). There might be consequences for custom ViewHelpers, however in most cases this change will make a lot of custom validation code that was necessary until Fluid v5 obsolete.
s2b
added a commit
that referenced
this pull request
Aug 15, 2025
Fluid v4.2.0 introduced a new API to process component and ViewHelper arguments (see #1062). To avoid breaking changes in Fluid v4 with how ViewHelpers handle their arguments, a `LenientArgumentProcessor` has been introduced which has been used exclusively for ViewHelpers. Components have used the new `StrictArgumentProcessor` from the beginning. With this breaking change, this is now unified: `StrictArgumentProcessor` is now used for ViewHelper arguments as well. This allows us to define an API in a follow-up patch that allows developers to define their custom argument processing and validation logic or extend/wrap the existing logic by Fluid. The `StrictArgumentProcessor` deals with argument types in a stricter way: If the supplied argument value doesn't meet the type requirement, an exception is thrown. For scalar types, automatic type conversion is happening in a processing step to avoid errors that can be easily solved by Fluid itself (like "string is required, integer given"). There might be consequences for custom ViewHelpers, however in most cases this change will make a lot of custom validation code that was necessary until Fluid v5 obsolete.
s2b
added a commit
that referenced
this pull request
Aug 18, 2025
Fluid v4.2.0 introduced a new API to process component and ViewHelper arguments (see #1062). To avoid breaking changes in Fluid v4 with how ViewHelpers handle their arguments, a `LenientArgumentProcessor` has been introduced which has been used exclusively for ViewHelpers. Components have used the new `StrictArgumentProcessor` from the beginning. With this breaking change, this is now unified: `StrictArgumentProcessor` is now used for ViewHelper arguments as well. This allows us to define an API in a follow-up patch that allows developers to define their custom argument processing and validation logic or extend/wrap the existing logic by Fluid. The `StrictArgumentProcessor` deals with argument types in a stricter way: If the supplied argument value doesn't meet the type requirement, an exception is thrown. For scalar types, automatic type conversion is happening in a processing step to avoid errors that can be easily solved by Fluid itself (like "string is required, integer given"). There might be consequences for custom ViewHelpers, however in most cases this change will make a lot of custom validation code that was necessary until Fluid v5 obsolete.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fluid allows ViewHelpers to specify their API by using
AbstractViewHelper::registerArgument(), which is usually called ininitializeArguments()of the ViewHelper. Internally,ArgumentDefinitionis used to represent the provided argument information and constraints.
Among those is the ability to specify the type of an argument as well
as if the argument should be a required argument.
While the required status is already validated at the parser level, the
argument types are validated by the ViewHelper implementation. However,
in most cases, Fluid's built-in validation method by
AbstractViewHelperis used. Unfortunately, this implementation has many flaws:
not "bool")
you might receive an integer in your ViewHelper implementation, even
if the argument has been defined as "string")
In order to fix this in a future Fluid version without introducing too many
hard-to-debug breaking changes, a new API is introduced which extracts
validation functionality from the
AbstractViewHelperand allowsalternative implementations in the future. It also adds the possibility
to pre-process arguments before their validity is checked, which will
allow implicit type conversions in the future (e. g. convert "int" to "string").
As a first step, the existing helper methods
isValidType()andgetFirstElementOfNonEmpty()are deprecated and extracted intoa
LenientArgumentProcessor, which mimicks the current validationbehavior. Like the current implementation, it doesn't modify the argument
types, but rather passes them along unmodified.
The new API is then called for the pre-processing step in
ViewHelperInvokeras well as the validation step inAbstractViewHelper.In this first implementation, it isn't possible yet to replace the default
implementation with an alternative.