首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >找不到'Pusher‘类

找不到'Pusher‘类
EN

Stack Overflow用户
提问于 2017-07-12 16:50:35
回答 5查看 16.3K关注 0票数 12

当我安装Pusher包时,我得到一个错误"Class 'Pusher‘not found“。

EN

回答 5

Stack Overflow用户

发布于 2017-07-30 05:27:04

Claudio的诊断是正确的,命名空间Pusher是在版本3中添加的;但是更改Laravel文件不是推荐的解决方案。

更好的方法是在config/app.php中创建别名。在“Aliases”键下,将以下内容添加到"Third Party Aliases“部分的数组中:

代码语言:javascript
复制
'Pusher' => Pusher\Pusher::class,
票数 34
EN

Stack Overflow用户

发布于 2017-07-18 00:47:51

(OP在问题中发布了以下答案。潜在的问题是pusher-php-server的版本3引入了一个名称空间,因此现在需要use Pusher\Pusher。)

创建此命令:

代码语言:javascript
复制
namespace App\Console\Commands;

use Illuminate\Support\Facades\File;
use Illuminate\Console\Command;

class FixPusher extends Command
{

    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'fix:pusher';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Fix Pusher namespace issue';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $broadcastManagerPath = base_path('vendor/laravel/framework/src/Illuminate/Broadcasting/BroadcastManager.php');
        $pusherBroadcasterPath = base_path('vendor/laravel/framework/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php');

        $contents = str_replace('use Pusher;', 'use Pusher\Pusher;', File::get($broadcastManagerPath));
        File::put($broadcastManagerPath, $contents);

        $contents = str_replace('use Pusher;', 'use Pusher\Pusher;', File::get($pusherBroadcasterPath));
        File::put($pusherBroadcasterPath, $contents);
    }
}

然后在composer.json文件中添加"php artisan fix:pusher"

代码语言:javascript
复制
"post-update-cmd": [
   "php artisan fix:pusher",
   "Illuminate\\Foundation\\ComposerScripts::postUpdate",
   "php artisan optimize"
]
票数 4
EN

Stack Overflow用户

发布于 2017-07-26 19:37:07

在Pusher版本3中,我意识到Pusher\Pusher的名称空间发生了变化。如果在设置.env、BROADCAST_DRIVER=pusher时由composer进行配置,则会显示错误。查看日志,您可以找到问题所在,位于以下文件中:

'vendor/laravel/framework/src/Illuminate/Broadcasting/BroadcastManager.php"

。有必要更改Pusher\Pusher的引用,而不是像图像中那样的Pusher:

然后找到函数PusherBroadCaster并将引用Pusher更改为Pusher\Pusher。

vendor/laravel/framework/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php

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

https://stackoverflow.com/questions/45052853

复制
相关文章

相似问题

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