Skip to content

refactor: let attributes declare what they register - #462

Merged
ogorzalka merged 3 commits into
release/v13.36.0from
refactor/attributes-declarations
Oct 12, 2026
Merged

ogorzalka merged 3 commits into
release/v13.36.0from
refactor/attributes-declarations

Conversation

@ogorzalka

Copy link
Copy Markdown
Member

First step of extracting the attributes into pollora/attributes (roadmap, short term). Nothing moves yet: Pollora\Attributes stops reaching Laravel and the framework's services, so the next PR can move it as is. No class name changes.

What changes

  • Post type and taxonomy attributes (69) implement ConfiguresArguments::configureArguments(array): array, a pure function of their own values; the discoveries apply it. The method attributes (AdminCol, RegisterMetaBoxCb, MetaBoxCb, MetaBoxSanitizeCb, UpdateCountCallback) implement ConfiguresArgumentsWithMethod: the discovery builds the callback, the attribute says where it goes. Custom attributes implementing HandlesAttributes still go through handle().
  • #[WpRestRoute\Method] keeps its data and HTTP verb validation; WpRestRouteRegistrar (WpRest module) registers the route, unchanged.
  • handle() removed from Action, Filter, WpRestRoute, Method: HookDiscovery and WpRestDiscovery register hooks and routes themselves.
  • Default names (post type/taxonomy slugs, meta keys, WP-CLI commands) come from an internal Naming helper; a parity test pins it to Str::snake() / Str::kebab(). Pollora\Support\Slug delegates to it.
  • Architecture test 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).
  • Deprecated: PostTypeAttribute, TaxonomyAttribute (no built-in attribute extends them), removed in 15.0.
  • PHPStan baseline: 3 entries fewer (the registrar is typed on the wrapper).

Bug fixed on the way

A public #[Action]/#[Filter] method in a #[PostType] or #[Taxonomy] class was registered twice: the discovery called Action::handle() with its configuration object as the instance. Reproduced on a project (#[Action('wp_footer')] on a post type): 500 call_user_func(): ... PostTypeConfiguration does not have a method "footerProbe". With this branch: 200, method run once.

Non-regression

  • 1975 tests (1954 before: −13 tests of the removed handle(), rewritten as HookDiscoveryTest against the discovery; +34 new), PHPStan 0, type coverage 99.2 %.
  • On pollora-test (develop + this diff): get_post_type_object() / get_taxonomy() dumped for the 10 post types and 11 taxonomies, identical with and without the change; REST routes starter/v1/status and /projects answer byte for byte the same.

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.
@ogorzalka
ogorzalka merged commit ecc3a12 into release/v13.36.0 Oct 12, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant