Psr-4 composer autoload without adding namespace in autoload_psr4.php

I use a custom repository in github in the project that contains my toolbox.

The project correctly imports the package inside the / vendor directory, but I cannot use any class because it does not load the contents of the package.

My batch file composer.json looks like this:

{ "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, the composer.json file looks like this:

  "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 file after performing the composer update, the linker dump looks like this: 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?

+6
source share
1 answer

This answer also applies here.

Since you provide an entry like "type: package" in "repositories", you will disable the composer.json file in the package.

And there is no startup definition defined in the package definition, so the package does not load automatically at all.

Decision. Do not use an entry like "type: package" for your repositories and which have a composer.json file inside.

+10
source

Source: https://habr.com/ru/post/973213/


All Articles