Skip to content

Increase template controller DI support#71

Merged
richstandbrook merged 28 commits into
masterfrom
feature/template-controller-di
May 20, 2026
Merged

Increase template controller DI support#71
richstandbrook merged 28 commits into
masterfrom
feature/template-controller-di

Conversation

@tommitchelmore
Copy link
Copy Markdown
Collaborator

@tommitchelmore tommitchelmore commented May 18, 2026

This PR introduces a robust context-aware Dependency Injection system for Template Controllers and adds Macroable proxy objects for Timber 2 alignment. Full backward compatibility is maintained; existing controller signatures and Timber integrations remain unaffected.

Controller Dependency Injection

  • Implemented automatic resolution and injection of WordPress/Timber objects based on request context.
  • Full support for both Timber base classes and Rareloop\Lumberjack proxy classes (Post, Term, User, PostQuery).
  • Recommendation: Type-hinting Rareloop\Lumberjack proxy objects is preferred to leverage added Macroable support and framework-specific utilities.
  • Supported types: Post, Term, User, PostQuery (including PostCollectionInterface).
  • Supports polymorphic subclasses (e.g. App\Post\Book) and nullable type-hints.
  • Introduced AbstractContextResolver using a Template Method pattern to centralize reflection, validation, and instance verification logic.
  • Added app.resolvers configuration support to allow user-defined resolver registration with precedence over core logic.
  • Configured Invoker priority chain: User Resolvers > Core Resolvers > Router Resolvers.

Macroable Proxy Objects

  • Added Rareloop\Lumberjack proxy classes for PostQuery, Term, and User. All proxies implement the Macroable trait.

Context Handling and Helpers

  • Introduced Rareloop\Lumberjack\Http\TimberContext collection wrapping the default Timber context.
  • Implemented dot-notation support for get(), set(), and has().
  • Overrode ArrayAccess (offsetGet, offsetExists) to ensure Illuminate\Support\Arr::get() compatibility with dot-notation on the context object.
  • Modified TimberResponse to support Arrayable and Collection context objects.

Bootstrapping and Performance

  • Bound WP_Query into the container in RegisterRequestHandler.
  • Registered TimberContext as a singleton in TimberServiceProvider.
  • Optimized DI loop performance by removing Collection overhead in core resolution.
  • Refactored provider bindings to eliminate runtime array_reverse calls on every resolution.

Tom Mitchelmore added 13 commits May 18, 2026 09:44
- Refactor parameter resolution into a SOLID, registry-based architecture using native PHP-DI chains
- Add specialized context resolvers for Timber Post, Term, User, and PostType objects
- Support nullable typehints while maintaining strict enforcement for type mismatches
- Introduce Macroable proxies for Timber PostQuery, Term, User, and PostType to ensure ecosystem consistency
- Bind TimberContext as a shared singleton Collection for cross-component data orchestration
- Integrate view helpers and container-aware response instantiation into the base Controller
- Update context resolvers to support Timber 2 canonical patterns and subclasses
- Implement config-driven resolver registration in WordPressControllersServiceProvider
- Ensure correct resolver priority (User > Core > Router) by prepending to the chain
- Add Macroable proxy classes for PostQuery, PostType, Term, and User
- Implement full PHPUnit test suite for all new DI features and proxy objects
- Fix missing imports and static state leakage in existing tests
- Optimized AbstractContextResolver loop to avoid collection overhead
- Safeguarded PostTypeResolver against non-WordPress contexts
- Cleaned up WordPressControllersServiceProvider by extracting core resolver list
- Refactored PostQueryResolverTest to reduce repetition
- Verified TimberResponse recursion logic and fixed missing Arr import
…eview

- Optimized AbstractContextResolver loop to avoid collection overhead
- Safeguarded PostTypeResolver against non-WordPress contexts
- Cleaned up WordPressControllersServiceProvider by extracting core resolver list
- Refactored PostQueryResolverTest to reduce repetition
- Verified TimberResponse recursion logic and fixed missing Arr import
- DRYed up context resolvers by moving reflection and validation logic to AbstractContextResolver
- Simplified concrete resolvers to implement canResolveClass and resolveObject
- Added AbstractContextResolverTest to cover common DI edge cases (built-ins, nullables, mismatches)
- Optimized existing resolver tests by removing repetitive boilerplate
- DRYed up context resolvers by moving reflection and validation logic to AbstractContextResolver
- Simplified concrete resolvers to implement canResolveClass and resolveObject
- Added AbstractContextResolverTest to cover common DI edge cases (built-ins, nullables, mismatches)
- Optimized existing resolver tests by removing repetitive boilerplate
- Optimized WordPressControllersServiceProvider by defining core resolvers in priority order
- Cleaned up AbstractContextResolverTest by using a shared test stub
- Verified all DI resolver tests and linting
…lumberjack-core into feature/template-controller-di
@tommitchelmore tommitchelmore marked this pull request as ready for review May 19, 2026 08:52
@tommitchelmore tommitchelmore added this to the v8.3.0 milestone May 19, 2026
Tom Mitchelmore added 9 commits May 19, 2026 11:14
- Implemented Term::termClass() to resolve mapped taxonomy classes
- Implemented User::userClass() to resolve mapped user classes via filters
- Added comprehensive unit tests and verified 100% coverage on new methods
Comment thread src/Http/Resolvers/AbstractContextResolver.php
Comment thread src/Http/Resolvers/PostQueryResolver.php
Comment thread src/Providers/WordPressControllersServiceProvider.php Outdated
Comment thread src/Post.php Outdated
Comment thread src/PostQuery.php Outdated
Comment thread src/PostType.php Outdated
Comment thread tests/Unit/Http/Responses/TimberResponseTest.php
Copy link
Copy Markdown
Collaborator

@AliceKLWilliams AliceKLWilliams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you have removed the view method - can you update the MR description to remove that part.

Comment thread src/Http/Resolvers/PostQueryResolver.php Outdated
Comment thread src/Http/Resolvers/PostQueryResolver.php Outdated
Comment thread src/Http/Resolvers/PostQueryResolver.php Outdated
Comment thread src/Http/Resolvers/PostResolver.php Outdated
Comment thread src/Providers/TimberServiceProvider.php Outdated
Comment thread tests/Unit/Http/Resolvers/NullableMultiParameterTest.php Outdated
Comment thread tests/Unit/Http/Resolvers/PostQueryResolverTest.php
Comment thread tests/Unit/Http/Resolvers/TermResolverTest.php
Comment thread tests/Unit/TermTest.php Outdated
Comment thread tests/Unit/UserTest.php Outdated
Comment thread src/Post.php Outdated
@AliceKLWilliams AliceKLWilliams self-requested a review May 20, 2026 15:01
@richstandbrook richstandbrook merged commit 270a11e into master May 20, 2026
6 checks passed
@tommitchelmore tommitchelmore deleted the feature/template-controller-di branch May 21, 2026 07:27
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.

3 participants