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?

Run composer dump-autoload to update the autoloader.

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

Composer require local package, The way to link to a local, in-development package is to first add in your main project's composer.json config config/composition-root.php local vendor/ autoload.php'; $bar = new Bar(); $foo = new Foo($bar); $foo->greet();. 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

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

Basic usage, How to autoload PHP classes the Composer way? the use of the built-in Composer autoloader for the packages that we installed. In the In the previous tutorial, we saw that all it takes to autoload Packagist libraries is to add at the top of our The best tutorial on using composer for loading local classes. In the previous tutorial, we saw that all it takes to autoload Packagist libraries is to add at the top of our scripts the following line that requires the Composer built-in autoloader: require_once __DIR__ . '/vendor/autoload.php'; But when working with our own classes (or with non-packagist classes) we may need to be somewhat more savvy

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

PHP composer autoload, 4 Steps to first Dummy Local Package. Create Packages directory. /app /temp +/packages /vendor composer.json. Create First Package. Start with something simple like filesystem or string utils. Move first Class to new package directory. Autoload with Composer. Composer is the most awesome tool for any PHP developer that made managing dependencies for any application packages hassle-free. In the following sections, I am not going to talk about the main…

Composer Local Packages for Dummies, Assume you are creating a new php package that will be shipped via composer/ packagist. Developing composer packages locally In your composer.json file you need to specify the package name and the PSR-4 autoload definition. Inside the application you need to add a new repository definition. In the composer.json file you will find the data that composer needs in order to work with, and manage the package that you have just installed. In our example: { "require": { "fzaninotto/faker": "^1.5" } } When you open the vendor folder, you’ll find the autoloader file (autoload.php) that comes free

Developing composer packages locally, The way to link to a local, in-development package is to first add in your main project's composer.json a udl/udl.php"}' --file composer.json. After that composer require "udl.php @dev" Generating optimized autoload files Hi, I'm using Ubuntu 16.04 LTS with PHP 7.0.8. I've installed composer with this command: sudo apt install composer No errors occurred during the installation:

Composer Install Local Package. The way to link to a local…, Symlink a local Composer package for development purposes. In PHP world Composer is currently the industry standard handling third-party packages. you need to specify the package name and the PSR-4 autoload definition Now inside the application that uses the package you need to add a new� require_once 'vendor/autoload.php' After including this line, you can start using any library you referenced straight away. Finally, just like all other package managers, composer helps you to keep all your packages updated. Other benefits of using Composer. There are other areas where composer will help you improve your workflow.

Comments
  • I found a solution here after searching a lot : stackoverflow.com/a/30457277/5645769
  • 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.
  • These file are frequently overwritten.