不能 运行 tools(PHP-Auth/delight-im) inside vendor

Cant run tools(PHP-Auth/delight-im) inside vendor

我正在尝试运行这个密码验证https://github.com/delight-im/PHP-Auth#creating-a-new-instance

我遵循他们的教程以及作曲家的教程。

目录:

Main
   |
   ->src
   |   |
   |   ->tools
   |         |
   |         ->authentication
   |         |
   |         ->db
   |
   ->vendor 

作曲家

 {
"name": "***",
"autoload": {
    "psr-4": {
        "Source\": "src/"
    }
},
"authors": [
    {
        "name": "***",
        "email": "***"
    }
],
"require": {
    "delight-im/auth": "dev-master",
    "cboden/ratchet": "^0.4",
    "laravel/laravel": "^5.8",
    "twig/twig":"^2.0",
}

}

身份验证文件夹中的文件:

require_once "../../../vendor/autoload.php";

use Source\tools\db;

$dbConfig = new db\dbconfig("users");

$credentials = $dbConfig->setDb();

$pdo_connection =  new PDO("mysql:host=$localhost;dbname=$database_schema",
                   $credentials["UserName"], $credentials["PassWord"]);

$auth = new \Delight\Auth\Auth($pdo_connection);

db 文件夹中的文件

namespace Source\tools\db;
class dbconfig  
{
  .....
}

我可以使用 use Source\tools\db; 来定义 dbconfig 所以我想自动加载正在为此工作。

但是当尝试使用这行代码时 $auth = new \Delight\Auth\Auth($pdo_connection); 我收到以下错误: 致命错误:未捕获错误:Class 'Delight\Auth\Auth' 未在(为保护隐私而删除的目录)/src/tools/authentication/validate_login_credentials.php:17 中找到 Class 'Delight\Auth\Auth' 堆栈跟踪:#0 {main } 投入

我是namespace/composer的新手,请原谅我的无知。

有谁知道如何解决这个错误?

我刚刚试过了,它以这种方式工作,在顶部

require __DIR__ . '/vendor/autoload.php';

之后数据库配置

$db = new \PDO('mysql:dbname=my-database;host=localhost;charset=utf8mb4', 'my-username', 'my-password');

$auth = new \Delight\Auth\Auth($db);

echo get_class($auth);

没有错误,请仔细检查您的供应商自动加载文件,看来您输入的路径有误。

使用以下内容更新您的作曲家文件

"require": {
    "delight-im/auth": "dev-master", // "delight-im/auth": "^8.1"
    "cboden/ratchet": "^0.4",
    "laravel/laravel": "^5.8",
    "twig/twig":"^2.0",
 }

替换

"delight-im/auth": "dev-master",

"delight-im/auth": "^8.1"

保存并执行 composer 更新命令。