webman gateway-worker自定义Gateway

sanergo
//process的配置文件
<?php

use Webman\GatewayWorker\Gateway;
use app\plugin\GatewayWorker\Gateway as GatewayPlugin;
use Webman\GatewayWorker\BusinessWorker;
use Webman\GatewayWorker\Register;

return [
    'gateway-websocket' => [
        'handler'     => GatewayPlugin::class,
        'listen'      => 'websocket://0.0.0.0:7272',
        'count'       => cpu_count(),
        'reloadable'  => false,
        'constructor' => ['config' => [
            'lanIp'           => '127.0.0.1',
            'startPort'       => 2300,
            'pingInterval'    => 10,
            'pingNotResponseLimit' => 1,
            'pingData'        => '',
            'registerAddress' => '127.0.0.1:1236',
            'onConnect'       => function(){},
        ]]
    ],
    ...省略
];
// 复制webman的Gateway
<?php

namespace app\plugin\GatewayWorker;

class Gateway extends \GatewayWorker\Gateway
{
    /**
     * @var string 
     */
    protected $_autoloadRootPath = '';

    public function __construct($config)
    {
        foreach ($config as $key => $value)
        {
            $this->$key = $value;
        }

        //$this->router = array("\\app\\plugin\\GatewayWorker\\Gateway", 'routerBindNew');
        $this->router = array("\\GatewayWorker\\Gateway", 'routerBind');
    }
}

原计划是自定义一个Gateway用来自定义路由"routerBind "
提示process error: class app\plugin\GatewayWorker\Gateway not exists
请问应该怎么写才对??

574 1 0
1个回答

Tinywan

你这命名空间不正确吧

  • sanergo 2024-04-09

    路径是没问题的 是在app/plugin/gateway-worker目录 在vscode都可以直接跳转到类。

  • Tinywan 2024-04-10

    重启下试试

  • six 2024-04-10

    目录名不对,按照你的命名空间应该是 app/plugin/GatewayWorker 目录,大小写都要对应上才行

  • sanergo 2024-04-10

    确实是这样的,主要是复制的webman的gateway-worker,用的也是"-",直接转大写就行了,大概看了下,应该是autoloader有转换。

×
🔝