我已经为一包旧类设置了这样的文件夹结构
vendorname/legacy/src/ClassA.php
namespace VendornameLegacy;
class ClassA{}
vendorname/legacy/src/Folder/Class2.php
namespace VendornameLegacyFolder;
class FolderClass2{}
与作曲家一起,我正在从类似的github存储库中加载它:
"repositories": [
{
"type": "vcs",
"url": "git@bitbucket.org:username/vendorname-legacy-classes.git"
}
],
"require": {
"vendorname/legacy": "master@dev"
}
当我这样加载这样的课程时,它有效:
use VendornameLegacyClassA;
$a = new ClassA();
但是,我的子文件夹中都没有工作:
use VendornameLegacyFolderFolderClassB;
$b = new FolderClassB();
Class 'Vendorname\Legacy\Folder\FolderClassB' not found
我已经用文件供应商 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"
}
}
}
您需要为Composer.json
定义一件事{
"autoload": {
"psr-4": {"Vendorname\Legacy\": "vendorname/legacy/src/"}
}
}