实例化 Pusher 时出现致命错误 - 找不到 class

Fatal error when instanciating Pusher - Can't find class

我有一个项目要测试和试用,结构如下:

app/
    controllers/
        HomeController.php
    handlers/
    models/
vendor/
    composer/
    psr/
    pusher/
        pusher-php-server/
            src/
                Pusher.php
                PusherException.php
                PusherInstance.php
            tests/
            composer.json
    autoload.php
index.php

我试图在我的索引文件中要求 Pusher 自动加载器:

require 'vendor/autoload.php';

以下是:

// autoload.php @generated by Composer
   require_once __DIR__ . '/composer/autoload_real.php';
   return ComposerAutoloaderInite16b90ab01042d2a69b1d54243c9e23a::getLoader();

现在,在我的 HomeController.php 中,我有以下代码:

namespace App\controllers;

use \App\handlers\Views as View;
use \App\models\Home_model as Home;
use \App\controllers\SessionController;
use \Pusher\Pusher as Pusher;

class HomeController {

    private $pusher;

    public function __construct() {
        $options = array(
            'cluster' => 'hmm',
            'encrypted' => true
        );

        $this->pusher = new Pusher(
            'secret',
            'secret',
            'secret',
            $options
        );
    }

    public function index() {

        $data['message'] = 'hello world';
        $this->pusher->trigger('my-channel', 'my-event', $data);

        return $this->view->render('views/home/index.php');
    }
}    

但是这个returns我错了:

Fatal error: Class 'Pusher\Pusher' not found in

而且我不确定我做错了什么。有人可以解释我做错了什么吗?

composer.json 中,我得到以下信息:

{
    "name": "pusher/pusher-php-server",
    "description" : "Library for interacting with the Pusher REST API",
    "keywords": ["php-pusher-server", "pusher", "rest", "realtime", "real-time", "real time", "messaging", "push", "trigger", "publish", "events"],
    "license": "MIT",
    "require": {
        "php": "^5.4 || ^7.0",
        "ext-curl": "*",
        "psr/log": "^1.0"
    },
    "require-dev": {
        "phpunit/phpunit": "^4.8 || ^5.7"
    },
    "autoload": {
        "psr-4": {
            "Pusher\": "src/"
        }
    },
    "autoload-dev": {
        "psr-4": { "": "tests/" }
    },
    "config": {
        "preferred-install": "dist"
    },
    "extra": {
        "branch-alias": {
            "dev-master": "3.0-dev"
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true
}

在 Github 上,他们提到库依赖于 cURL 和 JSON 模块。

不确定这是否与我的问题有关? 我仍然卡住了,所以非常感谢任何帮助。

此外,我正在使用 .htaccess 文件来重写我的网址。

我已经让你的代码与 index.php 旁边的 composer.json 一起工作:

{
    "name": "awesome/project",
    "type": "project",
    "license": "MIT",
    "authors": [
        {
            "name": "Author",
            "email": "author@gmail.com"
        }
    ],
    "autoload": {
        "psr-4": {
            "": ""
        }
    },
    "require": {
        "pusher/pusher-php-server": "dev-master"    
    }
}

然后 运行 composer install。 我的 index.php 内容:

<?php

require 'vendor/autoload.php';

use app\controllers\HomeController;

$ctrl = new HomeController();