简体   繁体   中英

Composer autoloading psr-4 not adding namespace to autoload_psr4.php

I am using in a project a custom repository in github that contains my set of instruments.

The project correctly imports the package inside the /vendor directory,but i cannot use any of the class, because it is not autoloading the contents of the package.

My package composer.json file looks as follows:

{
"name": "mynamespace/toolbox",
"description": "Asdfoobar.",
"keywords": ["mynamespace", "toolbox"],
"license": "MIT",
"require": {
    "php": ">=5.4"          
},
"require-dev": {
    "codeception/codeception": "2.0.2",
    "codeception/specify": "0.3.6",
    "codeception/verify": "0.2.7",
    "mockery/mockery": "0.9.1"
},
"autoload": {
    "psr-4": {
        "Mynamespace\\": "src/Mynamespace",
        "Mocks\\": "tests/Mocks"
    }
},
"scripts": {
    "post-install-cmd": [

    ],
    "post-update-cmd": [
        "php vendor/bin/codecept run"
    ]
},
"config": {
    "preferred-install": "dist"
},
"minimum-stability": "stable"

}

Inside the project instead, the composer.json file looks as follows:

    "require": {
       [...stuff...]
       "Mygitrepo/toolbox": "dev-master" 
    },
    "repositories": [        
    {
        "type": "package",
        "package": {
            "name": "Mygitrepo/toolbox",
            "version": "master",
            "source": {
                "url": "https://github.com/Mygitrepo/toolbox.git",
                "type": "git",
                "reference": "master"
            }
        }
    }
]

The final autoload_psr4.php after doing composer update, composer dump looks like following: No trace of "Mynamespace"

return array(
  'Monolog\\' => array($vendorDir . '/monolog/monolog/src/Monolog'),
  'Ivory\\LuceneSearchBundle\\' => array($vendorDir . '/egeloen/lucene-search-bundle'),
  'Facebook\\' => array($vendorDir . '/facebook/php-sdk-v4/src/Facebook'),
);

Any help ?

This answer applies here as well.

Because you are providing a "type:package" entry in "repositories", you are disabling the composer.json file in the package.

And there is no autoloading defined in the package definition, so the package is not autoloaded at all.

Solution: Don't use the "type:package" entry for repositories you own and which have a composer.json file inside.

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