我为遗留类包
设置了这样的文件夹结构vendorname/legacy/src/ClassA.php
namespace Vendorname\Legacy;
class ClassA{}
vendorname/legacy/src/Folder/Class2.php
namespace Vendorname\Legacy\Folder;
class FolderClass2{}
使用作曲家我从这样的github回购中加载:
"repositories": [
{
"type": "vcs",
"url": "git@bitbucket.org:username/vendorname-legacy-classes.git"
}
],
"require": {
"vendorname/legacy": "master@dev"
}
当我像这样加载ClassA时,它可以工作:
use Vendorname\Legacy\ClassA;
$a = new ClassA();
但是我的子文件夹类都不起作用:
use Vendorname\Legacy\Folder\FolderClassB;
$b = new FolderClassB();
Class 'Vendorname\\Legacy\\Folder\\FolderClassB' not found
我已经使用文件vendor \ vendorname \ composer.json
定义了源文件夹{
"name": "vendorname/legacy",
"description": "Vendorname Legacy classes",
"require": {
"php": ">=5.3.0"
},
"autoload": {
"psr-4": {
"Vendorname\\Legacy\\": "src"
}
},
"extra": {
"branch-alias": {
"master": "master"
}
}
}
答案 0 :(得分:3)
你需要为你的composer.json定义更多的东西
{
"autoload": {
"psr-4": {"Vendorname\\Legacy\\": "vendorname/legacy/src/"}
}
}