3

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?

Vivendi
  • 20,047
  • 25
  • 121
  • 196

3 Answers3

3

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"
        }
    ]
}
simkin
  • 31
  • 4
1

Run composer dump-autoload to update the autoloader.

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

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
  • This options isn't working. The command doesn't display any errors, but it can't find my local classes either. I simply ran the command in my `www` directory. – Vivendi Jul 20 '15 at 18:26
-2

Add your class to vendor/composer/autoload_psr4.php or vendor/composer/autoload_classmap.php

jsxqf
  • 557
  • 3
  • 13