ssmiff / attribute-collector
Installs: 7
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/ssmiff/attribute-collector
Requires
- composer/class-map-generator: ^1.6
- psr/log: ^3.0
Requires (Dev)
- mockery/mockery: ^1.6
- phpunit/phpunit: ^12.4
README
Collect all public class/method/properties attributes into a single registry.
Usage
There are two built in memoizers, FileMemoizer and InMemoryMemoizer. These can optionally be used to cache the results of the discovery process.
Example:
use Ssmith\AttributeCollector\Cache\FileMemoizer; use Ssmith\AttributeCollector\ComposerClassMap; use Ssmith\AttributeCollector\Tests\fixtures\Attributes\TargetClass; include __DIR__ . '/vendor/autoload.php'; $classMap = new ComposerClassMap([__DIR__ . '/tests/fixtures']); $memoize = new InMemoryMemoizer(); $logger = new PrsLogger(); $discovery = new Ssmith\AttributeCollector\ClassAttributeCollector($classMap, $memoize, $logger); $registry = $discovery->buildRegistry(); $allAttributesByName = $registry->forAttribute(MyAttribute::class); $allAttributesOnClass = $registry->forClass(MyClass::class); $allAttributesOnClassMethod = $registry->forMethod(MyClass::class, 'myMethod'); $allAttributesOnClassProperty = $registry->forProperty(MyClass::class, 'myProperty'); $distinctAttributes = $registry->count();