methods = new PublicMethods(); return json_encode(["Civi::pipe" => ['jsonrpc20']]); } /** * @inheritDoc */ protected function onRequest(string $requestLine): ?string { return JsonRpc::run($requestLine, function($method, $params) { $method = str_replace('.', '_', $method); if (!preg_match(self::METHOD_REGEX, $method)) { throw new \InvalidArgumentException('Method not found', -32601); } if (!is_callable([$this->methods, $method])) { throw new \InvalidArgumentException('Method not found', -32601); } return call_user_func([$this->methods, $method], $this, $params); }); } /** * @inheritDoc */ protected function onException(string $requestLine, \Throwable $t): ?string { $error = JsonRpc::createResponseError([], $t); return \json_encode($error); } /** * @param bool $trusted * @return PipeSession */ public function setTrusted(bool $trusted): PipeSession { if ($this->trusted !== NULL && $this->trusted !== $trusted) { throw new \CRM_Core_Exception('Cannot modify PipeSession::$trusted after initialization'); } $this->trusted = $trusted; return $this; } /** * @return bool */ public function isTrusted(): bool { // If this gets called when the value is NULL, then you are doing it wrong. return $this->trusted; } }