Ratchet Fatal Error: Class 'MyApp \ Chat' not found in C: \ wamp \ www \ bin \ chat-server.php

0

I'm trying to learn how to use the new Html5 API, WebSocket, and I decided to start by testing Ratchet, which is a php library. Anyway, I followed all the steps of this tutorial to create a basic chat link and when running on the terminal it does not find the class Chat.php. I have changed this place class several times and nothing works. The structure of the files looks like this:

bin
   chat-server.php
src
   MyApp
      Chat.php
vendor
   autoload.php
   (...)
composer.json
composer.lock

My files look like this:

composer.json

{
  "autoload": {
    "psr-0": {
        "MyApp": "src"
    }
 },
 "require": {
    "cboden/ratchet": "0.3.*"
 }
}

chat-server.php

<?php
use Ratchet\Server\IoServer;
use MyApp\Chat;

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

$server = IoServer::factory(
    new Chat(),
    8080
);

$server->run();

Chat.php

<?php
namespace MyApp;
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;

class Chat implements MessageComponentInterface {
    public function onOpen(ConnectionInterface $conn) {
    }
    public function onMessage(ConnectionInterface $from, $msg) {
    }
    public function onClose(ConnectionInterface $conn) {
    }
    public function onError(ConnectionInterface $conn, \Exception $e) {
    }
}

ps: I found some similar issues in forums, but no procedure solved

    
asked by anonymous 30.07.2014 / 18:12

1 answer

1

I had the same problem, but I managed to solve it as follows, after doing all that you did, re-enter the folder of your project via terminal and run: composer update after that run the server with the command also in the terminal php bin/chat-server.php

    
01.08.2014 / 17:28