These are just some double-quoted PHP strings that need double-quotes.
*/
public function connect(string $command): array {
if ($this->process) {
- throw new \RuntimeException("Client error: Already connected");
+ throw new \RuntimeException('Client error: Already connected');
}
$desc = [['pipe', 'r'], ['pipe', 'w'], ['pipe', 'a']];
$line = stream_get_line($this->pipes[1], $this->bufferSize, "\n");
$this->welcome = json_decode($line, TRUE);
if ($this->welcome === NULL || !isset($this->welcome['Civi::pipe'])) {
- throw new \RuntimeException("Protocol error: Received malformed welcome");
+ throw new \RuntimeException('Protocol error: Received malformed welcome');
}
return $this->welcome['Civi::pipe'];
}
*/
public function call(string $method, array $params, $id = NULL): array {
if (!$this->process) {
- throw new \RuntimeException("Client error: Connection was not been opened yet.");
+ throw new \RuntimeException('Client error: Connection was not been opened yet.');
}
$requestLine = json_encode(['jsonrpc' => '2.0', 'method' => $method, 'params' => $params, 'id' => $id]);
$responseLine = stream_get_line($this->pipes[1], $this->bufferSize, "\n");
$decode = json_decode($responseLine, TRUE);
if (!isset($decode['jsonrpc']) || $decode['jsonrpc'] !== '2.0') {
- throw new \RuntimeException("Protocol error: Response lacks JSON-RPC header.");
+ throw new \RuntimeException('Protocol error: Response lacks JSON-RPC header.');
}
if (!array_key_exists('id', $decode) || $decode['id'] !== $id) {
- throw new \RuntimeException("Protocol error: Received response for wrong request.");
+ throw new \RuntimeException('Protocol error: Received response for wrong request.');
}
if (array_key_exists('error', $decode) && !array_key_exists('result', $decode)) {
$response = static::handleMethodCall($parsed, $dispatcher);
}
else {
- // [sic] "Invalid Request" title-case is anomalous but dictated by standard.
+ // [sic] 'Invalid Request' title-case is anomalous but dictated by standard.
throw new \InvalidArgumentException('Invalid Request', -32600);
}
throw new \InvalidArgumentException('Parse error', -32700);
}
if (($request['jsonrpc'] ?? '') !== '2.0' || !is_string($request['method'])) {
- // [sic] "Invalid Request" title-case is anomalous but dictated by standard.
+ // [sic] 'Invalid Request' title-case is anomalous but dictated by standard.
throw new \InvalidArgumentException('Invalid Request', -32600);
}
if (isset($request['params']) && !is_array($request['params'])) {
public $raw;
public function __construct(array $jsonRpcError) {
- parent::__construct($jsonRpcError['error']['message'] ?? "Unknown JSON-RPC error",
+ parent::__construct($jsonRpcError['error']['message'] ?? 'Unknown JSON-RPC error',
$jsonRpcError['error']['code'] ?? 0,
$jsonRpcError['error']['data'] ?? []
);
* $session = new class {
* use LineSessionTrait;
* protected function onRequest(string $requestLine): ?string {
- * return "Thanks";
+ * return 'Thanks';
* }
* protected function onException(string $requestLine, \Throwable $t): ?string {
- * return "Oops";
+ * return 'Oops';
* }
* }
* $session->setIO(STDIN, STDOUT)->run();
}
}
- return json_encode(["Civi::pipe" => $flags]);
+ return json_encode(['Civi::pipe' => $flags]);
}
/**
*/
public function login(PipeSession $session, array $request) {
if (!function_exists('authx_login')) {
- throw new \CRM_Core_Exception("Cannot authenticate. Authx is not configured.");
+ throw new \CRM_Core_Exception('Cannot authenticate. Authx is not configured.');
}
$redact = function(?array $authx) {
return $redact(authx_login(['flow' => 'script', 'principal' => $principal]));
}
elseif ($principal && !$session->isTrusted()) {
- throw new AuthxException("Session is not trusted.");
+ throw new AuthxException('Session is not trusted.');
}
elseif (isset($request['cred'])) {
$authn = new \Civi\Authx\Authenticator();
$authn->setRejectMode('exception');
if ($authn->auth(NULL, ['flow' => 'pipe', 'cred' => $request['cred']])) {
- return $redact(\CRM_Core_Session::singleton()->get("authx"));
+ return $redact(\CRM_Core_Session::singleton()->get('authx'));
}
}
- throw new AuthxException("Cannot authenticate. Must specify principal/credentials.");
+ throw new AuthxException('Cannot authenticate. Must specify principal/credentials.');
}
/**