phpgithubcomposer-php

PHP Developing a composer package under vendor of the main project


I have a main php project that needs a php component developed by me, that i intend to reuse in other projects, the component is in the main project vendor directory. However pushing to Github the component, go to the main project, running composer update is time consuming. In order to speed up the development of the component, is there a way to include the local component project into the main project?


Solution

  • This is how I do local composer package development.

    1. Create a vendor-repo folder next to the vendor folder.
    2. Create a directory for the vendor and project name for example vendor-repo/vendorname/packagename
    3. Create a git repo inside the packagename folder and build your composer package complete with composer.json etc.
    4. Add your local repository to the main composer.json (the one that requires your package). You can also disable the packagist repo by adding the "packagist": false as per the example below. This will speed things up and is a good idea if you aren't using any packages from packagist.
    "repositories": [
        {
            "type": "path",
            "url": "vendor-repo/vendorname/packagename"
        },
        {
            "packagist": false
        }
    ]
    

    Then when you run composer update it will get your package from your local repo rather than needing to get it from GitHub.