44[ ![ Code Coverage] ( https://coveralls.io/repos/github/olvlvl/composer-attribute-collector/badge.svg?branch=main )] ( https://coveralls.io/r/olvlvl/composer-attribute-collector?branch=main )
55[ ![ Downloads] ( https://img.shields.io/packagist/dt/olvlvl/composer-attribute-collector.svg )] ( https://packagist.org/packages/olvlvl/composer-attribute-collector )
66
7- ** composer-attribute-collector** is a plugin for [ Composer] [ ] . Its ambition is to provide a
8- convenient way— and near zero cost—to retrieve targets of PHP 8 attributes . After the autoloader has
9- been dumped, the plugin collects attribute targets and generates a static file. These targets can be
10- retrieved through a convenient interface, without reflection. The plugin is useful when you need to
11- _ discover _ attribute targets in a codebase—for known targets you can use reflection.
7+ ** composer-attribute-collector** is a [ Composer] [ ] plugin designed to effectively _ discover _ PHP 8
8+ attribute targets, and later retrieve them at near zero cost, without runtime reflection . After the
9+ autoloader dump, it collects attributes and generates a static file for fast access. This provides a
10+ convenient way to _ discover _ attribute-backed classes, methods, or properties—ideal for codebase
11+ analysis. (For known targets, traditional reflection remains an option.)
1212
1313
1414
1515#### Features
1616
17- - Little configuration
17+ - Zero configuration
1818- No reflection in the generated file
19- - No impact on performance
19+ - Might improve performance
2020- No dependency (except Composer of course)
2121- A single interface to get attribute targets: classes, methods, and properties
2222- Can cache discoveries to speed up consecutive runs.
@@ -91,11 +91,11 @@ var_dump($attributes->propertyAttributes);
9191
9292Here are a few steps to get you started.
9393
94- ### 1\. Configure the plugin
94+ ### 1\. Configure the plugin (optional)
9595
96- The plugin only inspects paths and files specified in the configuration with the ` include ` property.
97- That is usually your "src" directory. Add this section to your ` composer.json ` file to enable the
98- generation of the "attributes" file when the autoloader is dumped .
96+ The collector automatically scans ` autoload ` paths of the root ` composer.json ` for a
97+ zero-configuration experience. You can override them via
98+ ` extra.composer-attribute-collector.include ` .
9999
100100``` json
101101{
@@ -162,8 +162,8 @@ Here are a few ways you can configure the plugin.
162162
163163### Including paths or files ([ root-only] [ ] )
164164
165- Use the ` include ` property to define the paths or files to inspect for attributes. Without this
166- property, the "attributes" file will be empty .
165+ The collector automatically scans ` autoload ` paths of the root ` composer.json ` , but you can override
166+ them via the ` include ` property .
167167
168168The specified paths are relative to the ` composer.json ` file, and the ` {vendor} ` placeholder is
169169replaced with the path to the vendor folder.
@@ -182,7 +182,7 @@ replaced with the path to the vendor folder.
182182
183183### Excluding paths or files ([ root-only] [ ] )
184184
185- Use the ` exclude ` property to exclude paths or files from inspection . This is handy when files
185+ Use the ` exclude ` property to exclude paths or files from scanning . This is handy when files
186186cause issues or have side effects.
187187
188188The specified paths are relative to the ` composer.json ` file, and the ` {vendor} ` placeholder is
@@ -277,9 +277,9 @@ PHP. If the plugin is too slow for your liking, try running the command with
277277** How do I include a class that inherits its attributes?**
278278
279279To speed up the collection process, the plugin first looks at PHP files as plain text for hints of
280- attribute usage. If a class inherits its attributes from traits, properties, or methods, it is
281- ignored. Use the attribute ` [#\olvlvl\ComposerAttributeCollector\InheritsAttributes] ` to force the
282- collection.
280+ attribute usage. If a class inherits its attributes from traits, properties, or methods, but doesn't
281+ use attributes itself, it will be ignored. Use the attribute
282+ ` [#\olvlvl\ComposerAttributeCollector\InheritsAttributes] ` to force the collection.
283283
284284``` php
285285trait UrlTrait
0 commit comments