如何将我自己的 class 添加到 ratchat 服务器

how to add my own class to ratchat server

我正在使用 ratchet 创建 websocket 服务器,但我遇到了问题....
如何编写我自己的 classes 并将它们用于此....

PHP :

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

    define ("ABSPATH" , "D:/MyProject/server/bin/");
    require_once ABSPATH."config.php";

    require_once ABSPATH."classes/clients.php";// <--- i required this file that
//it contain clients class 
//but when i want to use it i get error that this class notfound

    class Poker implements MessageComponentInterface {
        protected $clients;

        public function __construct(){   
            $this->clients = array();
        }
        public function onOpen(ConnectionInterface $conn) {

            $client = new clients($conn);//here i get error
            array_push($this->clients,$client);

        }
        public function onMessage(ConnectionInterface $from, $msg) {

    }
        public function onClose(ConnectionInterface $conn) {

        }
        public function onError(ConnectionInterface $conn, \Exception $e) {

        }
    }

我需要 class 文件

require_once ABSPATH."classes\clients.php";

但是在这一行我得到错误

$client = new clients($conn);// ERROR CLASS NOT FOUND

错误:

Fatal error: Class 'MyApp\clients' not found in D:\MyProject\server\src\MyAp
p\Poker.php on line 18

这是因为当前文件在命名空间中,但我假设您与客户端 class 的文件不在?

尝试添加

    namespace MyApp;

到 clients.php,如果你想创建一个新的专用命名空间,你将不得不 use 它就像你当前文件中的两行