【问题标题】:OAuth 2.0 Server PHP, interfaces not foundOAuth 2.0 服务器 PHP,未找到接口
【发布时间】:2014-05-09 18:44:48
【问题描述】:

OAuth 2.0 Server PHP 有一个小问题,我想在我的项目中使用它。这是我的项目的树视图:

/Model/ 包含管理API的所有类

/Lib/ 包含所有第三方库

对于“IO\Model”和库为“IO\Lib”的模型,根命名空间为“IO”。我遇到的问题来自命名空间,目前“IO\Lib\OAuth2\Storage\Pdo”类是众所周知的,但找不到接口。我以前在其他项目中从未遇到过这个问题。

OAuth 2.0 服务器 PHP 库到它自己的命名空间“OAuth2”。这是我的脚本 Auth.php:

namespace IO\Model;

use IO\Lib\OAuth2 as OAuth2;

class Auth {
  public function __construct() {
    $this->config = Config::getInstance();
    
    $storage = new OAuth2\Storage\Pdo(
      array(
        'dsn' => 'mysql:dbname='.$this->config->sql_database.';host='.$this->config->sql_host,
        'username' => $this->config->sql_user,
        'password' => $this->config->sql_password
      )
    );
    $server = new OAuth2\Server($storage);
  }
}

我收到了这个错误:

致命错误:在第 19 行的 /Lib/OAuth2/Storage/Pdo.php 中找不到接口“OAuth2\Storage\AuthorizationCodeInterface”

【问题讨论】:

  • 你没有使用 Composer 吗?

标签: php interface namespaces oauth-2.0


【解决方案1】:

看起来你们中的一个 OAuth2 库文件在其一个或多个文件中引用了 Oauth2\Storage\AuthorizationCodeInterface。问题是该库是独立的,并希望驻留在命名空间OAuth2 中。您将其放入命名空间IO\Lib\OAuth2

我不知道您使用哪种方法来加载文件(自动加载器?),但您应该以保留其命名空间的方式包含第三方库。

【讨论】:

    【解决方案2】:

    来自此参考:http://alexbilbie.com/2013/02/securing-your-api-with-oauth-2/

    您是否使用 composer 安装了 oauth ? 这是不自动加载界面的可能性(没有自动加载器)

    【讨论】:

      【解决方案3】:

      根据之前的答案,如果自动加载器失败,那么手动运行加载器的解决方案
      下面给出

      Check this link

      【讨论】:

        猜你喜欢
        • 2012-11-18
        • 2013-08-26
        • 1970-01-01
        • 2015-07-24
        • 2013-10-05
        • 2021-08-31
        • 2011-12-25
        • 2014-07-26
        • 2015-01-15
        相关资源
        最近更新 更多