gitdependenciescomposer-phppsr-4psr-0

How to add a new non-git private package/classes to a PHP application?


I have a small package with 6-7 files (i.e., main class, extending classes, interface, which can be viewed in this link) and I'd like not to use require_once method to connect these classes together.

What might be the correct way to do so?

Attempts

I have tried to add them to vendor directory using composer.

composer require our-new-package-private

and

composer require our-new-package-private ~1.0.0

It returns an error:

  [InvalidArgumentException]                                                                                                                         
  Could not find a matching version of package equity-usco. Check the package spelling, your version constraint and that the package is available i  
  n a stability which matches your minimum-stability (stable). 

Questions


Solution

  • Currently it's still not possible to create a composer package from a repository subfolder/ (Github Issue)

    You can follow this Packagist link to create your own package.

    Define Your Package

    Put a file named composer.json at the root of your package's repository, containing this information:

    {
        "name": "your-vendor-name/package-name",
        "description": "A short description of what your package does",
        "require": {
            "php": "^7.2",
            "another-vendor/package": "1.*"
        }
    }
    

    This is the strictly minimal information you have to give.

    For more details about package naming and the fields you can use to document your package better, see the about page.

    Commit The File

    Add the composer.json to your git or other VCS repository and commit it.

    Publish It

    Login or register on (the) site, then hit the submit button in the menu.

    [...]