📖 Example Tutorials
Each document in this section corresponds to a runnable example under examples/, complete with full code and line-by-line explanations. Working through them once beats reading the API tables ten times.
Packagist API Examples (Remote Operations, No PHP Required)
| Example | What it demonstrates | Difficulty |
|---|---|---|
| 🚀 basic_setup | Initialize the Packagist API client | Beginner |
| 📥 download_index | Download the complete package index | Beginner |
| 📋 list_packages | Fetch and process the package list | Beginner |
| 📊 get_statistics | Retrieve repository statistics | Beginner |
| 🔒 security_advisories | Retrieve security advisories | Intermediate |
| ⭐ popular_packages | Retrieve the most popular packages | Beginner |
| 🛡️ security_monitor | Build a security monitoring system | Advanced |
Composer CLI Examples (Local Operations, PHP+Composer Required)
| Example | What it demonstrates | Difficulty |
|---|---|---|
| 🚀 auto-install | Automatically install Composer + PHP (cross-platform) | Beginner |
| ⌨️ cli_basic_usage | Create a Composer instance, run basic commands | Beginner |
| 📦 cli_package_management | Install, update, add, remove, search packages | Intermediate |
| 🏗️ cli_project_management | Create projects, run scripts, platform checks, dependency analysis | Intermediate |
| 🔐 cli_security | Security audit, platform requirement checks, config validation | Intermediate |
| 🔍 cli_inspection | Package info, dependency trees, why analysis, funding & licenses | Intermediate |
| ⚙️ cli_configuration | composer.json operations, config, auth, repository management | Intermediate |
| 🌍 cli_global | Global install, update, remove packages | Intermediate |
| 🧩 cli_advanced | Satis private repos, command execution, version constraints, diagnostics, archiving, env vars | Advanced |
How to Run
bash
# Clone the repository
git clone https://github.com/scagogogo/composer-skills.git
cd composer-skills
# Run an example (security_monitor in this case)
go run examples/security_monitor/main.goRemote examples require no environment
The Packagist API examples (basic_setup, get_statistics, etc.) are pure Go — no PHP or Composer needed. Just clone and go run.
Local CLI examples require PHP
The cli_* series executes the local composer binary and requires PHP 7.4+ and Composer 2.0+ installed on your machine. If not installed, leverage the SDK's auto-install capability.
Learning Path
The recommended study order:
- basic_setup → Understand client initialization
- get_statistics / list_packages → Get familiar with common queries
- security_advisories → Step into security scenarios
- cli_basic_usage → Transition to local Composer operations
- cli_package_management → Master dependency management
- security_monitor / cli_advanced → Comprehensive hands-on
Each example is annotated with links to its corresponding SDK methods, making it easy to dive into the API reference.