Download the PHP package teewurst/psr4-advanced-wildcard-composer-plugin without Composer
On this page you can find all versions of the php package teewurst/psr4-advanced-wildcard-composer-plugin. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download teewurst/psr4-advanced-wildcard-composer-plugin
More information about teewurst/psr4-advanced-wildcard-composer-plugin
Files in teewurst/psr4-advanced-wildcard-composer-plugin
Package psr4-advanced-wildcard-composer-plugin
Short Description Adds a parser to enable composer, to be used with wildcards
License MIT
Informations about the package psr4-advanced-wildcard-composer-plugin
PSR4 Advanced Wildcard Composer Plugin
Adds a parser so Composer can handle wildcards in your autoload configuration. Because listing every single file by hand is so 2015.
Installation
How it works
Glob patterns and sprintf team up to dynamically replace content in the generated autoload file:
- GLOB braces define folders dynamically (e.g.
"/modules/{*Domain,*Module}/{*}/src") %splaceholders in namespaces match the GLOB findings (e.g."My\\Namespace\\%s\\%s\\")- GLOB is case-insensitive on Linux and Windows
- Argument switching works too, though we don't recommend it (e.g.
"My\\Namespace\\%2$s\\%1$s\\") - IDEs can't handle advanced wildcards (no auto-complete, no namespace recognition, etc.)
- Solution: run Composer in
--devmode — it generates acomposer.development.jsonwith all wildcards resolved. Your IDE will love you for it.
- Solution: run Composer in
Configuration options
- (Recommended) Add wildcards to
extra.teewurst/psr4-advanced-wildcard-composer-plugin.autoload.psr-4 - Set
extra.teewurst/psr4-advanced-wildcard-composer-pluginto a truthy value and use wildcards in your defaultautoload.psr-4 - File autoload wildcards: Use patterns in
autoload.filesto include matching files automatically (e.g."app/Helpers/{*}.php"instead of listing each file)
Example
composer.json:
File structure:
Equivalent to:
Limitations & Performance
A few things to keep in mind:
- Glob/IO/Performance: Yes,
dump-autoloadwill take a bit longer. That's the price of flexibility. - One folder level per replacement: The plugin is limited to one wildcard level per namespace segment. Adding more would get … interesting.
- Non-existent folders: You'll get weird results if folders don't exist. Create them first.
Development (Docker)
A Docker Compose setup is included so you don't need PHP or Composer installed locally.
To use a different PHP version, set PHP_VERSION before building:
Contributing
-
Create a dummy repository locally and add the plugin as a path dependency:
- Run
composer require teewurst/psr4-advanced-wildcard-composer-pluginin your dummy repo - Test your changes with
composer dump-autoload - xDebug users: Run
export COMPOSER_ALLOW_XDEBUG=1in your terminal session - All contributions must pass
composer testandcomposer analyse
CI & Quality
This project uses GitHub Actions for CI. Every push and pull request runs:
- Tests (PHPUnit) on PHP 7.4, 8.2, 8.3, 8.4, and 8.5
- Static analysis (PHPStan, level 4)
- Code coverage — the build fails if coverage drops below 100%
To require a passing build before merging, enable branch protection in your repo settings: Settings → Branches → Add rule and require the "Tests & Coverage" check.
All versions of psr4-advanced-wildcard-composer-plugin with dependencies
php Version ^7.4|^8.0
ext-json Version *