PHPDaemon\Servers\WebSocket\Pool::getRoute PHP Method

getRoute() public method

public getRoute ( string $path, object $client, boolean $withoutCustomTransport = false ) : mixed
$path string
$client object
$withoutCustomTransport boolean
return mixed
    public function getRoute($path, $client, $withoutCustomTransport = false)
    {
        if (!$withoutCustomTransport) {
            $this->trigger('customTransport', $path, $client, function ($set) use(&$result) {
                $result = $set;
            });
            if ($result !== null) {
                return $result;
            }
        }
        $routeName = ltrim($path, '/');
        if (!isset($this->routes[$routeName])) {
            if (Daemon::$config->logerrors->value) {
                Daemon::$process->log(get_class($this) . '::' . __METHOD__ . ' : undefined path "' . $path . '" for client "' . $client->addr . '"');
            }
            return false;
        }
        $route = $this->routes[$routeName];
        if (is_string($route)) {
            // if we have a class name
            if (class_exists($route)) {
                $this->onWakeup();
                $ret = new $route($client);
                $this->onSleep();
                return $ret;
            } else {
                return false;
            }
        } elseif (is_array($route) || is_object($route)) {
            // if we have a lambda object or callback reference
            if (!is_callable($route)) {
                return false;
            }
            $ret = $route($client);
            // calling the route callback
            if (!$ret instanceof Route) {
                return false;
            }
            return $ret;
        } else {
            return false;
        }
    }