4

this is the composer.json of my bundle (shortened)

{
    "name": "acme/my-bundle",
    "type": "library",
    "version": "0.5.0",
    "autoload": {
        "psr-4": {
            "Acme\\MyBundle\\": ""
        }
    }
}

and in my project:

"require": {
    "acme/my-bundle": "dev-master"
},

then i run composer install resulting in a installed.json like

[
    {
        "name": "acme/my-bundle",
        "version": "dev-master",
        "version_normalized": "9999999-dev",

        "type": "library",
        "installation-source": "source"
        //
        // here must be this:
        // "autoload": {
        //    "psr-4": {
        //        "Acme\\MyBundle\\": ""
        //    }
        // },
        // but these lines are missing!
        //
    }
]

and a autoload-psr4.php:

<?php

// autoload_psr4.php @generated by Composer

$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);

return array(
    /* here must be this:
     * 'Acme\\MyBundle\\' => array($vendorDir . '/acme/my-bundle'),
     * but this line is missing!
     */
);

the autoload is gone, and also other keys like require

what am i missing?

i also tried psr-0, but no success. autoload_namespaces.php is just an empty array.

auipga
  • 300
  • 3
  • 10
  • 1
    If that line is missing, then Composer installs a commit that has these lines missing in your repository. You probably messed up the Composer version detection because you are obviously using Git for version control, but did explicitly specify a version in the composer.json. I don't have a clear picture yet of what else is wrong, but here is my statement: Don't ever specify a version in composer.json when using version control systems where you can actually tag the version. You should probably delete the vendor folder and the composer.lock file and run `composer update` to try fix this. – Sven Jun 27 '14 at 17:43
  • @Sven: I completely deleted composer.lock and vendors folder after every attempt. Solution is already found. – auipga Jun 29 '14 at 00:32

1 Answers1

2

I did not mention, that I wanted to fetch a package from a private repo! This will make the difference!

So I had to re-specify the autoload

"require": {
    "acme/my-bundle": "dev-master"
},
"repositories": [
    {
        "type": "package",
        "package": {
            "version": "dev-master",
            "name": "acme/my-bundle",
            "source": {
                "url": "ssh://git@example.com/acme/my-bundle",
                "type": "git",
                "reference": "test"
            }, 
            //    THIS IS      |
            //    ADDITIONAL   V
            "autoload": {
                "psr-4": {
                    "Acme\\MyBundle\\": ""
                }
            }
        }
    }
]

see https://stackoverflow.com/a/24193122/816362 Thanks @zacharydanger

Community
  • 1
  • 1
auipga
  • 300
  • 3
  • 10
  • Well, you are probably doing it wrong then. Composer will be able to autodetect the `composer.json` of a project if you specify it as a "vcs" repository: `"type": "vcs", "url":"ssh://git@example.com/acme/my-bundle"`. Then Composer will use the definitions of autoloading of this project. If however you use the package type, you have to specify everything there and maintain it independently from the other library. This is a bad idea for maintenance. – Sven Jun 29 '14 at 00:41