laminas/laminas-component-installer
Composer plugin for Laminas and Mezzio apps that automates discovery, installation, and configuration of components/modules. Updates application config during composer install/update to enable packages with minimal manual setup.
This package, Laminas Component Installer, is a lightweight utility for managing component installation and autoloading in PHP/Laravel projects. While not Laravel-specific, it integrates seamlessly with Composer-based workflows (Laravel's default).
First steps:
composer require laminas/laminas-component-installer
First use case: Automate component installation in a Laravel package or custom deployment script:
use Laminas\ComponentInstaller\Installer\Installer;
$installer = new Installer();
$installer->install('vendor/package', 'path/to/install');
Service Providers:
Use the installer in a Laravel ServiceProvider to set up dependencies during boot:
public function boot()
{
$installer = new Installer();
if (!$installer->isInstalled('vendor/required-package')) {
$installer->install('vendor/required-package', storage_path('app/dependencies'));
}
}
Artisan Commands: Create a custom Artisan command for CLI-driven installation:
use Laminas\ComponentInstaller\Installer\Installer;
class InstallDependenciesCommand extends Command
{
protected function handle()
{
$installer = new Installer();
$installer->install('vendor/package', 'custom/path');
$this->info('Dependencies installed!');
}
}
Package Development:
Bundle the installer in your Laravel package’s composer.json as a dev dependency to automate setup for end users.
Post-Install Hooks:
Trigger installations after composer install via a post-install-cmd script in composer.json:
{
"scripts": {
"post-install-cmd": [
"Laminas\\ComponentInstaller\\Installer\\Installer::install('vendor/package', 'path')"
]
}
}
(Note: Requires custom scripting; use a Laravel event listener for tighter integration.)
Configuration-Driven:
Store installation paths/configs in config/installer.php and load them dynamically:
$config = config('installer.components');
foreach ($config as $component) {
$installer->install($component['vendor'], $component['path']);
}
Action Required: If your project uses PHP 8.1, update to PHP 8.2+ (8.5 now supported). Test thoroughly—some edge cases (e.g., legacy autoloading) may break.
php -v to check your PHP version. Enable strict_types=1 in composer.json to catch type-related issues early.Laravel Compatibility: Ensure your Laravel version supports PHP 8.5 (Laravel 10+ does). Check Laravel’s PHP requirements.
Autoloading Conflicts:
composer dump-autoload after installations.laravel-mix or vite for frontend dependencies to avoid duplication.Permissions:
$installer->setPermissions(0755); // Set during instantiation
storage/ and bootstrap/cache/ are writable (standard Laravel setup).Extension Points:
Laminas\ComponentInstaller\Installer\Installer to add pre/post-install logic:
class CustomInstaller extends Installer
{
protected function onInstall($source, $target)
{
// Add logic here (e.g., symlink creation)
}
}
Installed) to integrate with queues/jobs:
event(new Installed($source, $target));
Debugging:
$installer = new Installer(['verbose' => true]);
storage/logs/laravel.log for installation failures.PHP 8.5-Specific:
$installer->install(source: 'vendor/package', target: 'path').How can I help you explore Laravel packages today?