这是composer.json
{
"name": "uci/uci-wp-webauth",
"description": "Wordpress plugin for enabling WebAuth logging in for UCI users on a site-by-site basis.",
"type": "project",
"license": "GPL-3.0",
"minimimum-stability": "stable",
"autoload": {
"psr-4": {
"": "includes/"
}
},
"require": {
"uci/uci-lib": "dev-master#9097b4f"
},
"repositories": [
{
"type": "vcs",
"url": "git@github.com:username/uci-lib"
}
]
}
目录结构看起来像:
UCI
-WebAuth.php
和Webauth类是构造的:
namespace UCI;
class WebAuth {}
实现Webauth的类/代码:
namespace WebAuth;
use UCIWebAuth;
class Handler
{
public function __construct()
{
$this->init();
$this->webauth = new WebAuth();
由于某种原因,PHP继续报告:
Fatal error: Uncaught Error: Class 'UCIWebAuth' not found
在设置作曲家项目之前,我已经做过很多次了,但是这确实使我感到困惑。
如果没有指定的名称空间,您就无法具有PSR-4自动加载器,因此这基本上是错误的:
"autoload": {
"psr-4": {
"": "includes/"
}
},
您必须指定要映射到文件夹的命名空间,但是我宁愿用简单的classmap
替换整个psr-4
:
"autoload": {
"classmap:: ["includes/"]
},