无法在供应商内部运行工具(PHP-Auth / delight-im)

问题描述 投票:0回答:1

我正在尝试运行此密码身份验证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  
{
  .....
}

我可以使用Source \ tools \ db;定义dbconfig所以我想autoload正在为此工作。

但是当试图使用这行代码$ auth = new \ Delight \ Auth \ Auth($ pdo_connection);我收到以下错误:致命错误:未捕获错误:未找到类'Delight \ Auth \ Auth'(已移除dir以保护隐私)/src/tools/authentication/validate_login_credentials.php:17堆栈跟踪:#0 {main}抛出在

我是命名空间/作曲家的新手,请原谅我对此的无知。

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

php composer-php autoload
1个回答
1
投票

我只是尝试过它以这种方式工作,在顶部

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

之后是DB配置

$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);

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

使用以下内容更新您的composer文件

"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 update命令。

© www.soinside.com 2019 - 2024. All rights reserved.