Publish PHP SDKs manually

View as Markdown

This guide covers publishing PHP SDKs manually. For information on automating PHP SDK publishing, see Publish PHP SDKs automatically.

To share your generated PHP SDK with the community, you can publish it to Packagist. This enables other developers to install it using composer require.

Prerequisites

To publish your SDK to Packagist, you need the following:

  • A public Git repository (for example, GitHub or GitLab).
  • A Packagist account.
  • A valid composer.json with a name field in vendor/package format.

Initial setup

  1. Push your SDK to a public repository.

  2. Sign in to Packagist and click Submit.

  3. Enter your repository URL and submit. Packagist validates your composer.json and creates the package listing.

  4. Configure a GitHub webhook so Packagist automatically picks up new versions. In your repository settings, follow the instructions shown on your Packagist package page under Set up GitHub Hook.

Configure composer.json

Your SDK’s composer.json should include the following fields for a proper Packagist listing:

1{
2 "name": "your-vendor/your-sdk",
3 "description": "SDK for Your API",
4 "type": "library",
5 "license": "MIT",
6 "authors": [
7 {
8 "name": "Your Name",
9 "email": "your@email.com"
10 }
11 ],
12 "require": {
13 "php": "^8.0",
14 "guzzlehttp/guzzle": "^7.0",
15 "symfony/serializer": "^7.0",
16 "symfony/property-info": "^7.0",
17 "symfony/property-access": "^7.0",
18 "phpdocumentor/reflection-docblock": "^5.4"
19 },
20 "autoload": {
21 "psr-4": {
22 "YourSdk\\": "src/"
23 }
24 }
25}

Publish your PHP SDK to Packagist

To publish your SDK, do the following:

  1. Tag a release using semantic versioning.

    $git tag v1.0.0
    $git push origin v1.0.0
  2. Packagist picks up the tag automatically if the webhook is configured. Otherwise, trigger a manual update from your package page.

  3. Verify the publication at https://packagist.org/packages/your-vendor/your-sdk.

Publish updates

To publish updates to your SDK, do the following:

$# Tag a new version
$git tag v1.0.1
$git push origin v1.0.1

Best practices for publishing PHP SDKs

Use the following best practices when publishing your PHP SDK to Packagist:

  • Use semantic versioning.
  • Include a comprehensive README.md with installation and usage instructions.
  • Tag releases in Git rather than relying on branch-based version constraints.
  • Declare a specific PHP version constraint in composer.json (for example, "php": "^8.1").
  • Run your test suite before tagging a release.