Skip to content

Instantly share code, notes, and snippets.

@viniciusvts
Last active January 12, 2025 15:35
Show Gist options
  • Save viniciusvts/e86f1c79bdb4fda84dc56d9b67f9b529 to your computer and use it in GitHub Desktop.
Save viniciusvts/e86f1c79bdb4fda84dc56d9b67f9b529 to your computer and use it in GitHub Desktop.
Step by step to develop and publish a composer package

Step-by-step composer package

Developing the package

  • Create a composer.json file
{
  "name": "your-user/package-name",
  "description": "Package Description",
  "type": "library",
  "require": {
    "php": ">=7.4"
  },
  "autoload": {
    "psr-4": {
      "YourNamespace\\": "src/"
    }
  }
}
  • Create the src directory
  • Publish in github

Use and test locally in another local project

  • In the another local project add in composer.json:
{
  "repositories": [
    {
      "type": "path",
      "url": "../path/to/your/package"
    }
  ],
  "require": {
    "your-user/package-name": "@dev"
  }
}
  • Execute composer update to install the package

Register in Packagist

  • Create an account
  • Submit your package
  • Packagist will sychronize with your repository
  • Install your package with composer: composer require your-user/package-name

Another way to use your package

Github repository direct

  • Add in composer.json:
{
  "repositories": [
    {
      "type": "vcs",
      "url": "https://github.com/your-user/package-name"
    }
  ],
  "require": {
    "your-user/package-name": "main"
  }
}
  • Execute composer update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment