📦 Install
Installs Composer onto the system, automatically handling PHP dependencies and platform differences.
When to Use
Use this when you need to install Composer on the current machine (without specifying a version). The method first checks for PHP, then decides whether to use a package manager or direct download based on configuration, and finally delegates the actual installation to a platform-specific installer. 🚀
Signature
go
func (i *Installer) Install() errorParameters
| Parameter | Type | Description |
|---|---|---|
| None | — | Behavior is determined by the Config passed when creating the Installer |
Return Value
error:nilon success;ErrPHPNotFoundwhen PHP is missing;ErrInsufficientRightson insufficient permissions;ErrUnsupportedPlatformfor unsupported platforms. ⚠️
Example
go
package main
import (
"fmt"
"log"
"github.com/scagogogo/composer-skills/pkg/installer"
)
func main() {
i := installer.DefaultInstaller()
if err := i.Install(); err != nil {
log.Fatalf("installation failed: %v", err)
}
fmt.Println("Composer installed")
}Advanced
- If
Config.AutoInstallPHPistrue, it will attempt to auto-install PHP when missing. 🛠️ - On Linux, if
Config.PreferPackageManageristrue, it will prefer installing via apt/dnf etc., falling back to direct download on failure. 🐧 - To install a specific version, use
InstallVersion; for progress callbacks and retries, useInstallWithProgress. ⚡