3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * Collection of methods to expose to the pipe session. Any public method will be accessible.
20 * Send a request to APIv3.
23 * @param array $request
24 * Tuple: [$entity, $action, $params]
25 * @return array|\Civi\Api4\Generic\Result|int
27 public function api3($session, $request) {
28 $request[2] = array_merge(['version' => 3, 'check_permissions' => TRUE], $request[2] ??
[]);
29 return civicrm_api(...$request);
33 * Send a request to APIv4.
36 * @param array $request
37 * Tuple: [$entity, $action, $params]
38 * @return array|\Civi\Api4\Generic\Result|int
40 public function api4($session, $request) {
41 $request[2] = array_merge(['version' => 4, 'checkPermissions' => TRUE], $request[2] ??
[]);
42 return civicrm_api(...$request);
46 * Simple test; send/receive a fragment of data.
49 * @param mixed $request
52 public function echo($session, $request) {
60 * @param array{contactId: int, userId: int, user: string} $request
61 * @return array|\Civi\Api4\Generic\Result|int
63 public function login($session, $request) {
64 if (!function_exists('authx_login')) {
65 throw new \
CRM_Core_Exception("Cannot authenticate. Authx is not configured.");
67 $auth = authx_login($request, FALSE /* Pipe sessions do not need cookies or DB */);
68 return \CRM_Utils_Array
::subset($auth, ['contactId', 'userId']);
72 * Set ephemeral session options.
75 * @param array{maxLines: int, responsePrefix: int} $request
76 * Any updates to perform. May be empty/omitted.
77 * @return array{maxLines: int, responsePrefix: int}
78 * List of updated options.
79 * If the list of updates was empty, then return all options.
81 public function options($session, $request) {
83 'responsePrefix' => $session,
84 'maxLine' => $session,
88 if (!empty($request)) {
89 foreach ($request as $option => $value) {
90 if (isset($map[$option])) {
91 $storage = $map[$option];
92 $storage->{'set' . ucfirst($option)}($value);
93 $result[$option] = $storage->{'get' . ucfirst($option)}();
98 foreach ($map as $option => $storage) {
99 $result[$option] = $storage->{'get' . ucfirst($option)}();