未找到作曲家 PSR-4 自动加载 class

Composer PSR-4 Autoload class not found

几个小时以来,我一直在绞尽脑汁想弄清楚为什么自动加载对 "Authentication\auth()" 不起作用。 "dBase\db()" class 加载正常,但我得到:

Error: Class 'Authentication\auth' not found in /var/htdocs/dev/test.php on line 8

调用时 test.php.

根composer.json-

  "require": {
    "geeshoe/dbClass": "dev-develop",
    "geeshoe/authClass": "dev-master"
  },
  "autoload": {
    "psr-4": {
      "dBase\": "vendor/geeshoe/dbclass/",
      "Authentication\": "vendor/geeshoe/authClass/"
    }
  }

authClass.php header -

<?php
namespace Authentication;

use dBase\db;

class auth extends db
{

test.php -

if (file_exists("vendor/autoload.php")) {
    require "vendor/autoload.php";
} else {
    echo "Dam.. Something went wrong!";
}
$test = new \dBase\db();
$var = new \Authentication\auth();

如果有人能向我指出显而易见的事情,那就太好了。附带说明一下,出于测试目的,authClass->composer.json 文件中未指定自动加载。

这里的问题是实际上你没有使用 PSR-4。在 PSR-4 class 中,名称应该与文件名匹配。对于 db class 很好,因为 db class 位于 db.php 文件中,但 auth class 位于 authClass.php 文件中这就是问题所在。您应该将文件名更新为 auth.php

您可能需要 运行:

composer dump-autoload

还要记住,在实际包中,一个供应商包有一个命名空间,因此您不会为单个包创建多个命名空间,而只能创建一个