Download the PHP package pollora/discovery without Composer
On this page you can find all versions of the php package pollora/discovery. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download pollora/discovery
More information about pollora/discovery
Files in pollora/discovery
Package discovery
Short Description Find the PHP classes that carry attributes in themes, plugins and modules, and hand them to the code that registers them. Runs with or without Laravel.
License MIT
Homepage https://pollora.dev/core-concepts/auto-discovery/
Informations about the package discovery
Scans directories for PHP classes, reads each class once, and hands it to every discovery that wants it: one finds #[Action] methods, another #[PostType] classes, a third REST controllers. Each discovery collects what it found, then applies it in one pass. Scans are cached, a class is reflected once whatever the number of discoveries, and each item is applied once per request.
It is the engine behind Pollora's attributes, and it runs without Laravel: in a WordPress plugin, a Bedrock site or any PHP project.
Part of Pollora, the Laravel framework for WordPress. In a Pollora project it is already installed and wired: themes, plugins and modules are scanned for you, and your own discoveries are picked up from the container. See Auto-discovery.
Installation
Requires PHP 8.3+. It builds on spatie/php-structure-discoverer, which brings illuminate/collections; nothing else from Laravel is needed.
Quick start
A discovery says what it looks for in discover() and what to do with it in apply():
Point the engine at a directory and run it:
run() is discover() then apply(). Running again applies only what is new: an item is never applied twice.
Fitting it to an environment
Every dependency of DiscoveryEngine is optional. Without them, it builds classes by reflection, keeps no persistent cache and runs only the discoveries added to it.
| Argument | Contract | Default |
|---|---|---|
resolver |
InstanceResolverInterface, builds discoveries given by class name and the classes they find |
ReflectionInstanceResolver (constructor parameters filled from defaults and class types); ContainerInstanceResolver wraps any PSR-11 container |
registrar |
DiscoveryRegistrarInterface, adds the environment's discoveries before each run |
none |
cacheManager |
DiscoveryCacheManager, with a Spatie DiscoverCacheDriver |
no persistent cache |
logger |
PSR-3 | none |
skipClasses, skipPaths |
classes, or path fragments, never handed to discoveries | none |
Caching scans
Scanning walks every file of a location, so cache it outside development. Psr16DiscoverCacheDriver stores scans in any PSR-16 cache, such as WordPress transients or the object cache; Spatie's own drivers work too.
With warnOnSlowScans: true (meant for development, where the cache is off), a location that takes more than 250 ms to scan is logged: it usually holds node_modules, vendor or a build output.
Keeping a class out
Public API
The Pollora\Discovery\Domain\Contracts\* and Pollora\Discovery\Domain\Services\* namespaces are the stable contracts for writing discoveries and follow semantic versioning. Infrastructure classes may change in a minor version.
Testing
License
MIT. See LICENSE.
All versions of discovery with dependencies
illuminate/collections Version ^11.0|^12.0|^13.0
psr/container Version ^2.0
psr/log Version ^3.0
psr/simple-cache Version ^3.0
spatie/php-structure-discoverer Version ^2.4