简体   繁体   中英

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 ?

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"
        }
    ]
}

Run composer dump-autoload to update the autoloader.

For more info see: https://getcomposer.org/doc/03-cli.md#dump-autoload

将您的类添加到vendor/composer/autoload_psr4.phpvendor/composer/autoload_classmap.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM