Skip to content

📖 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)

ExampleWhat it demonstratesDifficulty
🚀 basic_setupInitialize the Packagist API clientBeginner
📥 download_indexDownload the complete package indexBeginner
📋 list_packagesFetch and process the package listBeginner
📊 get_statisticsRetrieve repository statisticsBeginner
🔒 security_advisoriesRetrieve security advisoriesIntermediate
popular_packagesRetrieve the most popular packagesBeginner
🛡️ security_monitorBuild a security monitoring systemAdvanced

Composer CLI Examples (Local Operations, PHP+Composer Required)

ExampleWhat it demonstratesDifficulty
🚀 auto-installAutomatically install Composer + PHP (cross-platform)Beginner
⌨️ cli_basic_usageCreate a Composer instance, run basic commandsBeginner
📦 cli_package_managementInstall, update, add, remove, search packagesIntermediate
🏗️ cli_project_managementCreate projects, run scripts, platform checks, dependency analysisIntermediate
🔐 cli_securitySecurity audit, platform requirement checks, config validationIntermediate
🔍 cli_inspectionPackage info, dependency trees, why analysis, funding & licensesIntermediate
⚙️ cli_configurationcomposer.json operations, config, auth, repository managementIntermediate
🌍 cli_globalGlobal install, update, remove packagesIntermediate
🧩 cli_advancedSatis private repos, command execution, version constraints, diagnostics, archiving, env varsAdvanced

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.go

Remote 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:

  1. basic_setup → Understand client initialization
  2. get_statistics / list_packages → Get familiar with common queries
  3. security_advisories → Step into security scenarios
  4. cli_basic_usage → Transition to local Composer operations
  5. cli_package_management → Master dependency management
  6. 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.

Released under the MIT License