【问题标题】:Fatal error: Uncaught Error: Class 'ClientRepository' not found致命错误:未捕获的错误:找不到类“ClientRepository”
【发布时间】:2020-03-02 17:10:58
【问题描述】:

我使用这个代码:

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

use League\OAuth2\Server\AuthorizationServer;
use League\OAuth2\Server\Exception\OAuthServerException;
use League\OAuth2\Server\Grant\PasswordGrant;
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;

$clientRepository = new ClientRepository();

但我得到错误:

致命错误:未捕获的错误:在中找不到类“ClientRepository” /home/a/public_html/app/oauth2.php:23 堆栈跟踪:#0 {main} 抛出 /home/a/public_html/app/oauth2.php 第 23 行

【问题讨论】:

  • 你可能也应该use ClientRepository,或者代替ClientRepositoryInterface
  • 我添加了使用 League\OAuth2\Server\Repositories\ClientRepository; 但不起作用
  • @Ogreucha 我读了那个回复,但对我不起作用
  • @user12330913 您必须创建自己的 ClientRepository 类,如该答案中所述。

标签: php oauth oauth-2.0 autoload


【解决方案1】:

也许,你忘记了命名空间:

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

use League\OAuth2\Server\AuthorizationServer;
use League\OAuth2\Server\Exception\OAuthServerException;
use League\OAuth2\Server\Grant\PasswordGrant;
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;

use NamespaceClass\ClientRepository; <-- edit

$clientRepository = new ClientRepository();

【讨论】:

  • 我添加了使用 League\OAuth2\Server\Repositories\ClientRepository; 但不起作用
  • 致命错误:未捕获的错误:在中找不到类'League\OAuth2\Server\Repositories\ClientRepository'
  • @user12330913 我认为您需要创建 ClientRepository 类,他必须实现 ClientRepositoryInterface oauth2.thephpleague.com/client-repository-interface
  • 如何创建这个类?在哪里?
猜你喜欢
  • 1970-01-01
  • 2023-03-25
  • 2018-09-06
  • 2018-05-11
  • 2020-11-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多