Repository navigation
Add the attributeServicesDirectories section - #6917
Closed
ondrejmirtes wants to merge 6 commits into
Closed
ondrejmirtes wants to merge 6 commits into
ondrejmirtes wants to merge 6 commits into
Conversation
…ttribute usage AutowiredService, NonAutowiredService, RegisteredRule, RegisteredCollector, GenerateFactory and AutowiredParameter are the attributes third parties will be able to use through attributeServicesDirectories. The new ApiAttributeRule listens on every attribute position and reports non-@api PHPStan attributes used outside PHPStan code. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vw4RxhEifXdnTPw57hG3Vw
…ces seam AttributeServicesRegistrar owns the target-to-definition logic and AttributeTargetsProvider is the single merged view over vendor/attributes.php and (soon) targets discovered in attributeServicesDirectories. No behavior change; DiscoveredAttributeTargets is empty until discovery lands. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vw4RxhEifXdnTPw57hG3Vw
…ner-cache keying The top-level section lists directories whose classes may carry PHPStan's DI attributes. Entries are absolutized relative to the declaring config file by NeonAdapter (also in ContainerFactory's pre-pass, so the resolver sees final paths before the container compiles). The resolver validates each directory against the owning Composer package's (or the root project's) autoload rules, gates the feature to PHP 8.0+, and computes the directory's contribution to the container cache key: a package version token for regularly installed vendor packages, per-file content hashes for project-own directories and path repositories. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vw4RxhEifXdnTPw57hG3Vw
…utoload data AttributeServicesDiscoverer enumerates candidate classes from the PSR-4 path contract and vendor/composer/autoload_classmap.php - no file is parsed - and reads the allowlisted attributes (AutowiredService, NonAutowiredService, RegisteredRule, RegisteredCollector, GenerateFactory, AutowiredParameter on constructor parameters) with native reflection. A cheap content prefilter keeps classes without PHPStan attributes from being autoloaded. Files that suggest a DI attribute but yield no autoloadable class, and PHPStan-internal attributes (#[ContainerExtension], #[ExtensionInterface], #[AutowiredExtensions], ...), are explicit errors. ContainerFactory seeds the discovery context before each container build; AttributeTargetsProvider merges the discovered targets with vendor/attributes.php lazily, so a container-cache hit loads nothing. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vw4RxhEifXdnTPw57hG3Vw
…services changes A directory listed in attributeServicesDirectories registers services straight from its classes, so a composer update of the owning package can affect the analysis of every file - the file-granular package re-seed is not enough. PackageDependencyResolver::resolveDirectoryPackage() also matches a directory that is a package's install path. The derivative (stub validator) container re-runs discovery through ContainerFactory::create(), covered by a regression test. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vw4RxhEifXdnTPw57hG3Vw
…to attributes Deterministically converts services:/rules: entries into #[AutowiredService], attributeServicesDirectories, and leaves everything it cannot express (setup, literal arguments, underivable tags, multi-registration, vendor classes) in place with the reason reported. PHP edits are position-guided line insertions (php-parser locates, plain text edits), NEON edits are order-mapped line surgery that aborts on any layout it cannot map. Before keeping the changes the command compiles the original and the converted configuration in fresh subprocesses (the current process has the classes loaded without the new attributes) and requires an identical tagged-services fingerprint, rolling everything back otherwise. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vw4RxhEifXdnTPw57hG3Vw
Member
Author
|
Opened from the old #6283 branch by mistake, superseded by the PR from attribute-services-section. |
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.
Implements the attribute-services part of #6283 step by step, on top of the merged
Conditional(#6914) and@apiattributes (#6916).New top-level section:
Classes in these directories can use all
@apiDI attributes:AutowiredService,NonAutowiredService,RegisteredRule,RegisteredCollector,GenerateFactory,Conditional, andAutowiredParameteron constructor parameters.Commits:
AttributeServicesRegistrarandAttributeTargetsProviderfromAutowiredAttributeServicesExtension. No behavior change, tagged services for levels 0/2/5/9/max with bleeding edge are identical.Conditionaltakes theNewExpressionmarker array instead ofnew.attributeServicesClassesparameter and are treated like classes fromservices:. A Composer update of a package owning a directory invalidates the whole result cache. Covered by a new e2e test.Performance, with phpstan-strict-rules and phpstan-deprecation-rules converted to attributes in
vendor/(56 services): cold container compile 684 ms with neon vs. 681 ms with attributes, cache hit 119 ms in both. Discovery takes 5.5 ms only while compiling, the resolver 3.4 ms on every run.Docs: phpstan/phpstan#15648