-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
fix: route options are not merged (inner filter overrides outer filter) #7981
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
<?php | ||
|
||
$routes->group('admin', static function ($routes) { | ||
$routes->group('users', static function ($routes) { | ||
$routes->group('admin', ['filter' => 'myfilter:config'], static function ($routes) { | ||
$routes->get('/', 'Admin\Admin::index'); | ||
$routes->group('users', ['filter' => 'myfilter:region'], static function ($routes) { | ||
$routes->get('list', 'Admin\Users::list'); | ||
}); | ||
}); |
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still confusing to me but I guess it's because we can have only one filter when
Config\Feature::multipleFilters
is disabled.Will this gonna end up as:
when
multipleFilters
option will be enabled?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. it is just because using
array_merge()
.https://3v4l.org/tskmm
It is the current behavior that filters are not merged, and also the reason why the Note in the user guide was added.
One possible behavior would be to merge filters as well, but then it would not be possible to delete filters in inner group. Multiple filters are already the default in 4.5.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point about removing filters.
I don't know... now I'm leaning towards staying with the current behavior and not inheriting anything. Because the new behavior seems even more confusing - it's inherited only if there are no other filters. I can imagine people adding a new filter over time and "losing" functionality.
Thanks to the current note, at least we have clear rules to follow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current behavior is not that straightforward either.
The current behavior is that if you don't pass an options array to the inner group, the outer options are inherited.
That's why when you set outer filter and add namespace option to inner group, the filter that set in outer suddenly will be gone for the inner route.
It seems that this issue is not so easy to conclude.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is a bit more complex than I thought at first. Especially if we add namespaces to it.
Personally, I would probably merge all the declared filters from the external to the internal group using
array_merge_recursive
and introduce something likefilterExclude
to remove the filters if needed. However, this seems a bit too complex... not sure if we want to make such big changes.Although the rules would be clear and need no further explanation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am very sorry for my translation.
Yes, to exclude the outside filter, I gave an example of
except
in the Config. Or we need to write such a filter for all routes except unnecessary ones (this is your option)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree with the new feature to exclude route filters in the
Config\Filter
.The
Config\Filter
and route filters are the same filters, but I think mixing these settings is a source of confusion.Also, I don't like to add a new key for excluding filters in the route option.
It also is complicated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, this does not cancel your method - we leave the outside filters empty and configure each route individually
I'm sorry, but what you don't like about the exception in the Config is a function of the framework. There is no other way to fine tune
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Config\Filter
defines filters for URI paths, not for routes.except
excepts the filter to the URI path inConfig\Filter
.https://codeigniter4.github.io/CodeIgniter4/incoming/filters.html#except-for-a-few-uris
Filters for a route are different things. If you specify a filter to a route, it is always applied.
The definitions in
Config\Filter
does nothing to route filters.What I don't like is to mix the two kind of filters. That is,
except
inConfig\Filter
excepts route filters, too.It is really complicated and confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michalsn @neznaika0 @MGatner I changed my mind. I sent another PR #8033 that behaves like michalsn expects in #7981 (comment)