首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未在Laravel 5中找到的类

未在Laravel 5中找到的类
EN

Stack Overflow用户
提问于 2017-01-24 14:30:19
回答 3查看 1.3K关注 0票数 2

我运行sudo composer require lcobucci/jwt来安装这些东西。

然后,我在我的文件上添加了use Lcobucci\JWT\Configuration;

然后,我开始使用示例代码

代码语言:javascript
复制
        $config = new Configuration(); // This object helps to simplify the creation of the dependencies
                               // instead of using "?:" on constructors.
        $token = $config->createBuilder()
        ->issuedBy('https://login.uat.telenet.be/openid') // Configures the issuer (iss claim)
        ->canOnlyBeUsedBy('site') // Configures the audience (aud claim)
        ->identifiedBy('888254e8-f1e8-4956-86fa-a6c0f61a6421', true) // Configures the id (jti claim), replicating as a header item
        ->issuedAt(time()) // Configures the time that the token was issue (iat claim)
        ->canOnlyBeUsedAfter(time() + 60) // Configures the time that the token can be used (nbf claim)
        ->expiresAt(time() + 3600) // Configures the expiration time of the token (exp claim)
        ->with('uid', 1) // Configures a new claim, called "uid"
        ->getToken(); // Retrieves the generated token

        $token->getHeaders(); // Retrieves the token headers
        $token->getClaims(); // Retrieves the token claims

        echo $token->getHeader('jti'); // will print "4f1g23a12aa"
        echo $token->getClaim('iss'); // will print "http://example.com"
        echo $token->getClaim('uid'); // will print "1"
        echo $token; // The string representation of the object is a JWT string (pretty easy, right?)

我一直在犯这个错误

未找到类'Lcobucci\JWT\Configuration‘

我怎么才能防止这种情况?

这是我的整个composer.json文件

代码语言:javascript
复制
{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=5.5.9",
        "laravel/framework": "5.1.*",
        "illuminate/html": "^5.0",
        "laracasts/utilities": "~2.0",
        "barryvdh/laravel-debugbar": "^2.0",
        "sammyk/laravel-facebook-sdk": "~3.0",
        "doctrine/dbal": "^2.5",
        "lcobucci/jwt": "^3.2"
    },
    "require-dev": {
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~4.0",
        "phpspec/phpspec": "~2.1",
        "mcamara/laravel-localization": "1.0.*"
    },
    "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/",
            "Helpers\\": "app/Helpers/"
        },
        "files": ["app/Helper.php"]
    },
    "autoload-dev": {
        "classmap": [
            "tests/TestCase.php"
        ]
    },
    "scripts": {
        "post-install-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "pre-update-cmd": [
        ],
        "post-update-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-root-package-install": [
            "php -r \"copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ]
    },
    "config": {
        "preferred-install": "dist"
    }
}
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2017-01-24 16:32:37

您已经安装了包的^3.2版本。如果查看此版本的代码和文档,就会发现没有Configuration对象;有一个Builder对象。

如果你只是去https://github.com/lcobucci/jwt,你将看到他们的主分支。根据他们的文件,他们目前正在编写下一个主要版本:

重要:这是我们下一个主要版本(v4)的文档,它将发生变化。如果您正在使用稳定版本,则应该转到分支3.2。

请确保查看正在使用的版本的文档:

https://github.com/lcobucci/jwt/tree/3.2

这是3.2的示例代码(您正在使用的版本):

代码语言:javascript
复制
use Lcobucci\JWT\Builder;

$token = (new Builder())->setIssuer('http://example.com') // Configures the issuer (iss claim)
                        ->setAudience('http://example.org') // Configures the audience (aud claim)
                        ->setId('4f1g23a12aa', true) // Configures the id (jti claim), replicating as a header item
                        ->setIssuedAt(time()) // Configures the time that the token was issue (iat claim)
                        ->setNotBefore(time() + 60) // Configures the time that the token can be used (nbf claim)
                        ->setExpiration(time() + 3600) // Configures the expiration time of the token (nbf claim)
                        ->set('uid', 1) // Configures a new claim, called "uid"
                        ->getToken(); // Retrieves the generated token


$token->getHeaders(); // Retrieves the token headers
$token->getClaims(); // Retrieves the token claims

echo $token->getHeader('jti'); // will print "4f1g23a12aa"
echo $token->getClaim('iss'); // will print "http://example.com"
echo $token->getClaim('uid'); // will print "1"
echo $token; // The string representation of the object is a JWT string (pretty easy, right?)
票数 1
EN

Stack Overflow用户

发布于 2017-01-24 14:34:52

尝试运行composer dumpauto命令

票数 3
EN

Stack Overflow用户

发布于 2020-03-13 14:04:50

首先,删除供应商文件夹并尝试使用命令重新安装composer

代码语言:javascript
复制
composer update 

已经面对一个问题两个多小时了,尝试不同的方法,然后尝试这个,我的问题解决了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41830759

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档