致命错误:接口';Ratchet\Wamp\WampServerInterface';在第6行的C:\wamp\www\myRatchetTutorial\src\MyApp\Pusher.php中找不到

致命错误:接口';Ratchet\Wamp\WampServerInterface';在第6行的C:\wamp\www\myRatchetTutorial\src\MyApp\Pusher.php中找不到,php,composer-php,ratchet,Php,Composer Php,Ratchet,我正在尝试运行Ratchet应用程序演示,但出现了此错误(在标题中) 我的文件结构: /bin/chat-server /bin/push-server /src/MyApp/Chat.php /src/MyApp/Pusher.php /vendor/ .. composer.json 这是我的Pusher类,在那里我得到了错误: <?php namespace MyApp; use Ratchet\ConnectionInterface; use Ratchet\Wamp\WampS

我正在尝试运行Ratchet应用程序演示,但出现了此错误(在标题中)

我的文件结构:

/bin/chat-server
/bin/push-server
/src/MyApp/Chat.php
/src/MyApp/Pusher.php
/vendor/ ..
composer.json
这是我的Pusher类,在那里我得到了错误:

<?php
namespace MyApp;
use Ratchet\ConnectionInterface;
use Ratchet\Wamp\WampServerInterface;

class Pusher implements WampServerInterface {

    public function onUnSubscribe(ConnectionInterface $conn, $topic) {
    }
    public function onOpen(ConnectionInterface $conn) {
    }
    public function onClose(ConnectionInterface $conn) {
    }
    public function onCall(ConnectionInterface $conn, $id, $topic, array $params) {
        // In this application if clients send data it's because the user hacked around in console
        $conn->callError($id, $topic, 'You are not allowed to make calls')->close();
    }
    public function onPublish(ConnectionInterface $conn, $topic, $event, array $exclude, array $eligible) {
        // In this application if clients send data it's because the user hacked around in console
        $conn->close();
    }
    public function onError(ConnectionInterface $conn, \Exception $e) {
    }


        /**
     * A lookup of all the topics clients have subscribed to
     */
    protected $subscribedTopics = array();

    public function onSubscribe(ConnectionInterface $conn, $topic) {
        $this->subscribedTopics[$topic->getId()] = $topic;
    }

    /**
     * @param string JSON'ified string we'll receive from ZeroMQ
     */
    public function onBlogEntry($entry) {
        $entryData = json_decode($entry, true);

        // If the lookup topic object isn't set there is no one to publish to
        if (!array_key_exists($entryData['category'], $this->subscribedTopics)) {
            return;
        }

        $topic = $this->subscribedTopics[$entryData['category']];

        // re-send the data to all the clients subscribed to that category
        $topic->broadcast($entryData);
    }

    /* The rest of our methods were as they were, omitted from docs to save space */
}
我尝试将此文件结构重新组织为:

C:\wamp\www\myRatchetTutorial\vendor\Ratchet\Wamp\WampServerInterface.php
但还是同样的错误

有没有办法解决这个问题

这是我的composer.json:

{
    "autoload": {
        "psr-0": {
            "MyApp": "src"
        }
    },
    "require": {
        "cboden/ratchet": "0.3.*",
        "react/zmq": "0.2.*|0.3.*"
    }
}
Push_server.php(包括自动加载文件):


您应该检查自动加载文件,例如,如果您使用的是Laravel,请查看文件夹:vendor/composer应该有一个名为autoload_classmap的文件,并找到以下行:

'Ratchet\\Wamp\\WampServerInterface' => $vendorDir . '/cboden/ratchet/src/Ratchet/Wamp/WampServerInterface.php',

如果该文件不包含任何与Ratchet相关的内容,请从项目根目录下的命令行

使composer dump autoload
删除composer.lock并创建此composer.json文件

{
    "autoload": {
        "psr-4": {
            "MyApp\\": "src"
        }
    },
    "require": {
        "cboden/ratchet": "^0.4.2",
        "react/zmq": "0.4.0"
    }
}
将终端cd上的内容写入根文件夹,然后写入:

composer install
这将为您提供正确的组件

您的文件夹应如下所示: bin/push-server.php src/Pusher.php

`<?php
    namespace MyApp;
    use Ratchet\ConnectionInterface;
    use Ratchet\Wamp\WampServerInterface;
   class Pusher implements WampServerInterface {
           protected $subscribedTopics = array();

           public function onSubscribe(ConnectionInterface $conn, $topic) {
                   $this->subscribedTopics[$topic->getId()] = $topic;
           }

           public function onUnSubscribe(ConnectionInterface $conn, $topic) {
           }

           public function onOpen(ConnectionInterface $conn) {
           }

           public function onClose(ConnectionInterface $conn) {
           }

           public function onCall(ConnectionInterface $conn, $id, $topic, array $params) {
           // In this application if clients send data it's because the user hacked around in console
                   $conn->callError($id, $topic, 'You are not allowed to make calls')->close();
          }

          public function onPublish(ConnectionInterface $conn, $topic, $event, array $exclude, array $eligible) {
    // In this application if clients send data it's because the user hacked around in console
                 $conn->close();
          }

          public function onError(ConnectionInterface $conn, \Exception $e) {
          }
          /**
          * @param string JSON'ified string we'll receive from ZeroMQ
          */

         public function onBlogEntry($entry) {
               $entryData = json_decode($entry, true);

        // If the lookup topic object isn't set there is no one to publish to
           if (!array_key_exists($entryData['category'], $this->subscribedTopics)) {
        return;
          }

        $topic = $this->subscribedTopics[$entryData['category']];

        // re-send the data to all the clients subscribed to that category
        $topic->broadcast($entryData);
   }

    /* The rest of our methods were as they were, omitted from docs to save space */
    }
从项目根文件夹运行“phpbin/pushserver.php”终端命令

如果有人觉得我的建议有用,请给我一个费率,因为stackoverflow阻止了我提问。我会非常感激的


谢谢大家!

Debes实施者todos los metodos que tiene Ratchet\Wamp\WampServerInterface en el-archivo/src/Pusher.php

`<?php
    namespace MyApp;
    use Ratchet\ConnectionInterface;
    use Ratchet\Wamp\WampServerInterface;
   class Pusher implements WampServerInterface {
           protected $subscribedTopics = array();

           public function onSubscribe(ConnectionInterface $conn, $topic) {
                   $this->subscribedTopics[$topic->getId()] = $topic;
           }

           public function onUnSubscribe(ConnectionInterface $conn, $topic) {
           }

           public function onOpen(ConnectionInterface $conn) {
           }

           public function onClose(ConnectionInterface $conn) {
           }

           public function onCall(ConnectionInterface $conn, $id, $topic, array $params) {
           // In this application if clients send data it's because the user hacked around in console
                   $conn->callError($id, $topic, 'You are not allowed to make calls')->close();
          }

          public function onPublish(ConnectionInterface $conn, $topic, $event, array $exclude, array $eligible) {
    // In this application if clients send data it's because the user hacked around in console
                 $conn->close();
          }

          public function onError(ConnectionInterface $conn, \Exception $e) {
          }
          /**
          * @param string JSON'ified string we'll receive from ZeroMQ
          */

         public function onBlogEntry($entry) {
               $entryData = json_decode($entry, true);

        // If the lookup topic object isn't set there is no one to publish to
           if (!array_key_exists($entryData['category'], $this->subscribedTopics)) {
        return;
          }

        $topic = $this->subscribedTopics[$entryData['category']];

        // re-send the data to all the clients subscribed to that category
        $topic->broadcast($entryData);
   }

    /* The rest of our methods were as they were, omitted from docs to save space */
    }

`显示您如何自动加载文件以及什么是
composer.js
-您的意思是
composer.json
?我如何自动加载文件?我上传了composer.json,够了吗?或者你想看什么?是的,我指的是composer.json..您确实在某处包含了
vendor/autoload.php
文件,不是吗?;)是的,我上传了我的push_server.php文件,它在哪里。有什么建议吗?文件结构有问题吗?嗨,我们只用英语。请翻译你的答案
`<?php
    namespace MyApp;
    use Ratchet\ConnectionInterface;
    use Ratchet\Wamp\WampServerInterface;
   class Pusher implements WampServerInterface {
           protected $subscribedTopics = array();

           public function onSubscribe(ConnectionInterface $conn, $topic) {
                   $this->subscribedTopics[$topic->getId()] = $topic;
           }

           public function onUnSubscribe(ConnectionInterface $conn, $topic) {
           }

           public function onOpen(ConnectionInterface $conn) {
           }

           public function onClose(ConnectionInterface $conn) {
           }

           public function onCall(ConnectionInterface $conn, $id, $topic, array $params) {
           // In this application if clients send data it's because the user hacked around in console
                   $conn->callError($id, $topic, 'You are not allowed to make calls')->close();
          }

          public function onPublish(ConnectionInterface $conn, $topic, $event, array $exclude, array $eligible) {
    // In this application if clients send data it's because the user hacked around in console
                 $conn->close();
          }

          public function onError(ConnectionInterface $conn, \Exception $e) {
          }
          /**
          * @param string JSON'ified string we'll receive from ZeroMQ
          */

         public function onBlogEntry($entry) {
               $entryData = json_decode($entry, true);

        // If the lookup topic object isn't set there is no one to publish to
           if (!array_key_exists($entryData['category'], $this->subscribedTopics)) {
        return;
          }

        $topic = $this->subscribedTopics[$entryData['category']];

        // re-send the data to all the clients subscribed to that category
        $topic->broadcast($entryData);
   }

    /* The rest of our methods were as they were, omitted from docs to save space */
    }