Skip to content

Allow injecting services into if and DynamicValues callables - #171

Draft
HypeMC wants to merge 1 commit into
sofascore:2.xfrom
HypeMC:callable-service-arguments
Draft

HypeMC wants to merge 1 commit into
sofascore:2.xfrom
HypeMC:callable-service-arguments

Conversation

@HypeMC

@HypeMC HypeMC commented Sep 28, 2026

Copy link
Copy Markdown
Member

Summary 📝

Static methods and closures used as the if condition or as a DynamicValues provider can now receive services in the parameters after the first one, which still receives the entity. They're resolved like controller arguments: autowiring by type, #[Target], and #[Autowire] with its variants.

#[PurgeOn(Post::class, if: static function (Post $post, FeatureFlags $flags, #[Autowire('%app.min_upvotes%')] int $min): bool {
    return $flags->isEnabled('purging') && $post->upvotes > $min;
})]

A new compiler pass reads the PurgeOn attributes of tagged controllers and the YAML mapping files, and registers a service locator per callable. At runtime, a new internal CallableInvoker passes the services in. Static methods are keyed by Class::method and closures by a hash of their DeepClone payload. Cache warmup now allows more than one parameter and reports required parameters that can't be resolved. It also validates static method DynamicValues providers, which weren't checked before. Since that exception now covers static methods too, the unreleased InvalidDynamicValuesClosureException is renamed to InvalidDynamicValuesProviderException.

Checklist ✅

  • Tests updated 🐛
  • Docs updated 📚
  • Changelog updated 📋
  • Breaking change ⚠️

@HypeMC HypeMC self-assigned this Sep 28, 2026
@codecov

codecov Bot commented Sep 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.45455% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.32%. Comparing base (562f3c6) to head (2d2e002).

Files with missing lines Patch % Lines
...n/RegisterCallableArgumentLocatorsCompilerPass.php 90.54% 7 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##                2.x     #171      +/-   ##
============================================
- Coverage     97.45%   97.32%   -0.13%     
- Complexity      688      740      +52     
============================================
  Files            75       77       +2     
  Lines          1648     1757     +109     
============================================
+ Hits           1606     1710     +104     
- Misses           42       47       +5     
Flag Coverage Δ
8.1 91.51% <88.31%> (+0.56%) ⬆️
8.2 91.56% <88.31%> (+0.55%) ⬆️
8.3 91.39% <88.31%> (+0.56%) ⬆️
8.4 92.42% <88.31%> (+0.50%) ⬆️
8.5 97.20% <95.45%> (-0.12%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
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