Repository navigation
refactor: let attributes declare what they register - #462
Merged
Merged
Conversation
Post type and taxonomy attributes implement ConfiguresArguments, a pure function of their own values, and the method attributes ConfiguresArgumentsWithMethod; the discoveries apply them. #[Method] routes are registered by WpRestRouteRegistrar, default names come from an internal Naming helper matching Str, and the dead handle() methods of Action, Filter and WpRestRoute are gone. Pollora\Attributes no longer reaches Laravel or a framework service, which an architecture test keeps. Fixes an #[Action] or #[Filter] method of a post type or taxonomy class being registered a second time on the discovery's configuration object.
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.
First step of extracting the attributes into
pollora/attributes(roadmap, short term). Nothing moves yet:Pollora\Attributesstops reaching Laravel and the framework's services, so the next PR can move it as is. No class name changes.What changes
ConfiguresArguments::configureArguments(array): array, a pure function of their own values; the discoveries apply it. The method attributes (AdminCol,RegisterMetaBoxCb,MetaBoxCb,MetaBoxSanitizeCb,UpdateCountCallback) implementConfiguresArgumentsWithMethod: the discovery builds the callback, the attribute says where it goes. Custom attributes implementingHandlesAttributesstill go throughhandle().#[WpRestRoute\Method]keeps its data and HTTP verb validation;WpRestRouteRegistrar(WpRest module) registers the route, unchanged.handle()removed fromAction,Filter,WpRestRoute,Method:HookDiscoveryandWpRestDiscoveryregister hooks and routes themselves.Naminghelper; a parity test pins it toStr::snake()/Str::kebab().Pollora\Support\Slugdelegates to it.tests/Unit/Attributes/ArchitectureTest.php: attributes may only use themselves and the enumerations that will travel with them (AjaxAccess,Behaviour,BindingFieldType,Control,Access,Every,Interval).PostTypeAttribute,TaxonomyAttribute(no built-in attribute extends them), removed in 15.0.Bug fixed on the way
A public
#[Action]/#[Filter]method in a#[PostType]or#[Taxonomy]class was registered twice: the discovery calledAction::handle()with its configuration object as the instance. Reproduced on a project (#[Action('wp_footer')]on a post type): 500call_user_func(): ... PostTypeConfiguration does not have a method "footerProbe". With this branch: 200, method run once.Non-regression
handle(), rewritten asHookDiscoveryTestagainst the discovery; +34 new), PHPStan 0, type coverage 99.2 %.get_post_type_object()/get_taxonomy()dumped for the 10 post types and 11 taxonomies, identical with and without the change; REST routesstarter/v1/statusand/projectsanswer byte for byte the same.