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

问题描述:

我试图运行Ratchet应用程序演示,但是出现此错误(在标题中)。致命错误:在第6行找不到C: wamp www myRatchetTutorial src MyApp Pusher.php中的接口'Ratchet Wamp WampServerInterface'

我的文件结构:

/bin/chat-server 
/bin/push-server 
/src/MyApp/Chat.php 
/src/MyApp/Pusher.php 
/vendor/ .. 
composer.json 

这是我的推杆课,在那里我得到了错误:

<?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 */ 
} 

我WampServerInterface是:

C:\wamp\www\myRatchetTutorial\vendor\cboden\ratchet\src\Ratchet\Wamp\WampServerInterface.php 

我试图重组此文件结构为:

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(包括自动加载文件):

<?php 
    require dirname(__DIR__) . '/vendor/autoload.php'; 

    $loop = React\EventLoop\Factory::create(); 
    $pusher = new MyApp\Pusher; 

    // Listen for the web server to make a ZeroMQ push after an ajax request 
    $context = new React\ZMQ\Context($loop); 
    $pull = $context->getSocket(ZMQ::SOCKET_PULL); 
    $pull->bind('tcp://127.0.0.1:5555'); // Binding to 127.0.0.1 means the only client that can connect is itself 
    $pull->on('message', array($pusher, 'onBlogEntry')); 

    // Set up our WebSocket server for clients wanting real-time updates 
    $webSock = new React\Socket\Server($loop); 
    $webSock->listen(8080, '0.0.0.0'); // Binding to 0.0.0.0 means remotes can connect 
    $webServer = new Ratchet\Server\IoServer(
     new Ratchet\Http\HttpServer(
      new Ratchet\WebSocket\WsServer(
       new Ratchet\Wamp\WampServer(
        $pusher 
       ) 
      ) 
     ), 
     $webSock 
    ); 

    $loop->run(); 
+0

显示你自动加载的文件,什么是如何'composer.js' - 你的意思'composer.json '? –

+0

我如何自动加载文件?我上传了composer.json,够了吗?或者你想看什么?是的,我的意思是composer.json .. – mrow

+0

你确实在某处包含了'vendor/autoload.php'文件,不是吗? ;) – helmbert

您应检查自动加载的文件,如果你正在使用L- 篷帐为例如,看看文件夹:供应商/作曲家应该有一个文件叫autoload_classmap并找到这一行:

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

如果文件不包含与棘轮什么,请composer dump-autoload在命令行