Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add local package to composers autoload.php

I'm working on a package that I later want to upload to packagist. But for now, I just want to develop it locally. But I can't find a way to have composer autoload my package without having it in Packagist.

Currently my project structure looks like this:

www/
  index.php
  composer.json
  composer.lock
  vendor/
    autoload.php
    acme/
      http/
        composer.json
        src/
          Request.php

I have manually placed my acme folder inside the vendor folder. I also added another composer.json inside the acme/http folder with the following contents:

{
    "name": "Acme/Http",
    "authors": [{
            "name": "Acme"
        }],
    "require": {
        "php": ">=5.3.0"
    },
    "autoload": {
        "psr-4": {
            "Acme\\Http\\": "src/"
        }
    }
}

Now, how can I now add my "local" project to composers autoload.php?

like image 589
Vivendi Avatar asked Dec 15 '25 08:12

Vivendi


1 Answers

Would be much more clean and clear to have acme/http outside vendor:

www/
  index.php
  composer.json
  composer.lock
  acme/
    http/
      composer.json
      src/
        Request.php
  vendor/
    autoload.php

Then use a repositories entry on the www/composer.json:

{
    "name": "foo/www",
    ...
    "require": {
        "acme/http": "*",
        ..
    },
    "repositories": [
        {
            "type": "path",
            "url": "./acme/http"
        }
    ]
}
like image 72
simkin Avatar answered Dec 16 '25 22:12

simkin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!