类';MyChatChat';在C:wampwwwinchat-server.php中


Class 'MyChatChat' not found in C:wampwwwinchat-server.php

我正在尝试从http://socketo.me/docs/hello-world,但是我一直收到这个错误。我试着四处移动文件,但没有成功,但我确信我没有把文件放在正确的位置。我对composer、websockets和psr-0完全陌生,关于PHP我还有很多东西要学。以下是我的路径树和来源:

C:'wamp'www'
        bin
           chat-server.php
        src
            MyChat
                Chat.php
        vendor
           {dependencies}+autoload.php
        composer.json
        composer.phar
        composer.lock

Chat.php

<?php
namespace MyChat;
require dirname(__DIR__) . ''vendor'autoload.php';
use Ratchet'MessageComponentInterface;
use Ratchet'ConnectionInterface;
class Chat implements MessageComponentInterface
{
    protected $clients;
    function __construct()
    {
        $this->clients=new 'SplObjectStorage();
    }
    function onOpen(ConnectionInterface $conn)
    {
        $this->clients->attach($conn);
        echo "New connection! ({$conn->resourceId})'n";
    }
    function onClose(ConnectionInterface $conn)
    {
        echo "Connection closed: {$conn->resourceId} 'n";
        $this->clients->detach($conn);
    }
    function onError(ConnectionInterface $conn, 'Exception $e)
    {
        echo "An error has occured: {$e->getMessage()}. Closing connection... 'n";
        $conn->close();
    }
    function onMessage(ConnectionInterface $from, $msg)
    {
        $receivers=count($this->clients)-1;
        foreach($this->clients as $client)
        {
            if($client!=$from)
            {
                $client->send($msg);
            }
        }
    }
}

聊天服务器.php

<?php
require dirname(__DIR__) . ''vendor'autoload.php';
use Ratchet'Server'IoServer;
use MyChat'Chat;
$server= IoServer::factory (new Chat() ,8080,'0.0.0.0');//0.0.0.0 is default, means accept all connections
$server->run();

composer.json

{
    "require": {
        "cboden/Ratchet": "0.2.*"
    },
    "autoload": {
        "psr-0": {
            "MyChat": "src"
        }
    }
}

我的php.exe位于C:''wamp''bin''php''php5.4.12中。如果能给我一个建议,我将不胜感激,我真的不知道我错在哪里了。

这有点晚了,但看起来您正在使用composer,所以您可能需要运行该安装程序?

从你的目录中试着运行每一个,看看这是否有帮助:

./composer.phar install --dev
./composer.phar update