⬇️ InstallComposerVersion
Downloads and installs a specific version of the Composer phar.
When to Use
Use this when you want to bypass the Installer instance and install a specific version (e.g. 2.5.1, preview) directly as a package-level function. 📚
Signature
go
func InstallComposerVersion(version string, installPath string, useSudo bool) errorParameters
| Parameter | Type | Description |
|---|---|---|
version | string | Version identifier: "1", "2", "latest", "preview", "stable", or a specific version like "2.5.1" |
installPath | string | Install directory; the phar and wrapper script will be written here |
useSudo | bool | Whether to use sudo for writing and permission changes |
Return Value
error: Returns anErrDownloadFailedwrapped error on download failure; returns the corresponding error on write failure. ⚠️
Example
go
package main
import (
"fmt"
"log"
"github.com/scagogogo/composer-skills/pkg/installer"
)
func main() {
if err := installer.InstallComposerVersion("2.5.1", "/usr/local/bin", true); err != nil {
log.Fatalf("installation failed: %v", err)
}
fmt.Println("Composer 2.5.1 installed")
}Advanced
- Download URLs for version aliases:
1→composer-1.phar;2/latest/stable→composer.phar;preview→composer-preview.phar; specific versions go throughdownload/{version}/composer.phar. 🌐 - Automatically creates an executable wrapper script (a shell script on Unix, a
.baton Windows). 🛠️ - The instance method
InstallVersionwraps this function; path and sudo are taken fromConfig. 🔗 - This method does not check for PHP; ensure PHP is installed before calling it. 🚫