tech-tips/Языки программирования/PHP/Composer/How to create a PHP package for Composer.md

1.4 KiB

It's as easy as 4 steps (minus the part where you code a reusable package in PHP) -- I was surprised too. Make sure before starting you've created a git repository in your project and committed your code. It's also required to have an account on Github and Packagist.

  1. Create a composer.json in your project:

    {
        "name": "your-brand-name/your-project",
        "type": "library",
        "description": "Your package description goes here",
        "keywords": ["relevant","tags","go","here"],
        "homepage": "<https://yourcompany.com>",
        "license": "MIT",
        "authors": [
            {
                "name": "Jordi Boggiano",
                "email": "j.boggiano@seld.be",
                "homepage": "<http://seld.be>",
                "role": "Developer"
            }
        ],
    }
    
  2. Create a new repository on your Github and push your local git (init if you haven't) to the remote Github repo.

  3. Submit your package to the Packagist

  4. Done! Your package should be online and Packagist should provide a sample Composer require with your project name (e.g. composer require username/package-name).
    You should be able to view your package live at:
    https://packagist.org/packages/your-username/package-name