Search code examples
composer-phpautoloadpsr-0psr-4

autoload psr-4 gets lost during install


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.


Solution

  • 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