oomphinc/composer-installers-extender
Installation Add the package to your project via Composer:
composer require --dev oomphinc/composer-installers-extender
Ensure composer/installers is also installed (required dependency).
Basic Configuration
Create/update composer.json to define custom installers for arbitrary package types (e.g., type: "laravel-module"):
{
"extra": {
"installer-paths": {
"modules/{$name}/": ["type:laravel-module"]
}
}
}
Define the installer in composer/installers-extender.json (auto-generated or manual):
{
"installers": {
"laravel-module": {
"type": "laravel-module",
"target": "modules/{$name}/",
"stub": "stubs/module.stub"
}
}
}
First Use Case Install a custom package type (e.g., a "module") via Composer:
composer require vendor/module-package:dev-main --dev
Verify the files are installed in modules/module-package/.
Custom Package Types
type: "laravel-theme", type: "config-package") in installers-extender.json.stubs/theme.stub) to generate boilerplate files (e.g., composer.json, README.md) during installation.Dynamic Paths
Leverage placeholders ({$name}, {$version}) in installer-paths for flexible directory structures:
"extra": {
"installer-paths": {
"resources/lang/{$locale}/{$name}/": ["type:translation-package"]
}
}
Post-Install Hooks
Combine with post-install-cmd in composer.json to run scripts after installation:
"scripts": {
"post-install-cmd": [
"php artisan vendor:publish --tag=module-config --force"
]
}
Multi-Package Projects
Use wildcards to group related packages (e.g., type: "laravel-*"):
"installer-paths": {
"packages/{$name}/": ["type:laravel-*"]
}
Service Providers Auto-register providers by parsing installed packages and publishing config files:
// In a custom Composer script
$packages = json_decode(file_get_contents('composer.lock'), true);
foreach ($packages['packages'] as $package) {
if (str_contains($package['type'], 'laravel')) {
$this->publishes([...], 'config');
}
}
Namespace Resolution
Use the installer to generate config/app.php entries dynamically:
// stubs/module.stub
<?php
return [
'providers' => [
// Auto-generated
],
];
Missing composer/installers
Class 'Composer\Installers\Installer' not found.composer/installers as a dev dependency:
composer require --dev composer/installers
Stub File Paths
stubs/module.stub) and referenced absolutely in installers-extender.json:
"stub": "stubs/module.stub"
Case Sensitivity
installer-paths keys are case-sensitive on some OSes (e.g., Modules/ vs modules/).Caching Issues
composer clear-cache
Conflicting Installers
installer-priority (if supported).composer require vendor/package --dry-run
COMPOSER_DEBUG=1 composer require vendor/package
vendor/composer/installed.json for installation details.Custom Installer Classes
Extend Composer\Installers\Installer for complex logic:
namespace App\Composer;
use Composer\Installers\Installer;
class ModuleInstaller extends Installer {
protected $stub = __DIR__ . '/../../stubs/module.stub';
// Custom logic here
}
Register in installers-extender.json:
"installers": {
"laravel-module": {
"class": "App\\Composer\\ModuleInstaller"
}
}
Dynamic Stubs
Use Twig templates for dynamic stubs (requires twig/twig):
"stub": "stubs/module.twig"
Example stub (stubs/module.twig):
{# module.stub #}
<?php
return [
'name' => '{{ name }}',
'version' => '{{ version }}',
];
Pre/Post Install Scripts
Hook into Composer lifecycle events via scripts:
"scripts": {
"post-install-cmd": [
"@php artisan module:discover"
]
}
installer-priority (if available) or namespace types (e.g., type: "myvendor-module").installer-paths unless explicitly handled (Composer may not resolve them correctly)./) in paths for cross-platform compatibility.How can I help you explore Laravel packages today?