ext/filter: Add Filter\Filter and Filter\Flag enums and support them in the filter extension - #24111
Open
arshidkv12 wants to merge 2 commits into
Open
arshidkv12 wants to merge 2 commits into
arshidkv12 wants to merge 2 commits into
Conversation
…in the filter extension APIs
…in the filter extension APIs
Member
|
Hi @arshidkv12. Please start a discussion on the mailing list. I'm not sure it's a good idea to extend this API further. |
Contributor
Author
|
Sure, I’ll start a discussion. |
Contributor
Author
|
Discussion thread: https://externals.io/message/132783 |
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.
The
filterextension currently exposes filter IDs and flags as integerconstants such as
FILTER_VALIDATE_INTandFILTER_FLAG_ALLOW_HEX.While these constants are well established and will remain available,
using integers for filter IDs and flags provides little type information
and makes the API harder to discover and use with modern PHP type
systems.
This added two backed enums:
Filter\Filterfor filter IDsFilter\Flagfor filter flagsAPI Changes
filter_input()The current signature is:
It becomes:
This allows:
and:
filter_var()The current signature is:
It becomes:
For example:
filter_input_array()The current signature is:
It becomes:
For example:
filter_var_array()The current signature is:
It becomes:
For example:
Filter Flags
Filter\Flagcan be passed directly where a filter flags integer isaccepted:
Multiple flags can still be combined using their backing values:
For array-based filter definitions, enum flags can be used as the
flagsvalue:The existing integer and scalar behavior of array-based filter options
is preserved.
Backwards Compatibility
This proposal does not remove or change the existing filter constants.
Existing code continues to work:
and:
The new enums are an additional way to specify filters and flags.
Existing integer arguments remain accepted by all affected APIs.
Duplicate Values
Some filter constants are aliases and have the same integer value.
Backed enums cannot contain multiple cases with the same backing value.
Therefore, only one enum case is provided for each unique backing value.
The existing constants remain unchanged, including aliases.
For example, if multiple
FILTER_FLAG_*constants have the same backingvalue, they cannot all be represented as separate cases of
Filter\Flag.Naming
The enum cases use names corresponding to the existing filter constant
names, without the
FILTER_orFILTER_FLAG_prefix.For example:
This keeps the relationship between the existing constants and the new
enums straightforward.