Merge pull request #15838 from demeritcowboy/getcasereport-split
[civicrm-core.git] / Civi / Api4 / Action / Setting / Get.php
CommitLineData
19b53e5b 1<?php
380f3545
TO
2
3/*
4 +--------------------------------------------------------------------+
41498ac5 5 | Copyright CiviCRM LLC. All rights reserved. |
380f3545 6 | |
41498ac5
TO
7 | This work is published under the GNU AGPLv3 license with some |
8 | permitted exceptions and without any warranty. For full license |
9 | and copyright information, see https://civicrm.org/licensing |
380f3545
TO
10 +--------------------------------------------------------------------+
11 */
12
13/**
14 *
15 * @package CRM
ca5cec67 16 * @copyright CiviCRM LLC https://civicrm.org/licensing
380f3545
TO
17 * $Id$
18 *
19 */
20
19b53e5b
C
21namespace Civi\Api4\Action\Setting;
22
23use Civi\Api4\Generic\Result;
24
25/**
26 * Get the value of one or more CiviCRM settings.
27 *
28 * @method array getSelect
29 * @method $this addSelect(string $name)
30 * @method $this setSelect(array $select)
31 */
32class Get extends AbstractSettingAction {
33
34 /**
35 * Names of settings to retrieve
36 *
37 * @var array
38 */
39 protected $select = [];
40
41 /**
42 * @param \Civi\Api4\Generic\Result $result
43 * @param \Civi\Core\SettingsBag $settingsBag
44 * @param array $meta
45 * @param int $domain
46 * @throws \Exception
47 */
48 protected function processSettings(Result $result, $settingsBag, $meta, $domain) {
49 if ($this->select) {
50 foreach ($this->select as $name) {
51 $result[] = [
52 'name' => $name,
53 'value' => $settingsBag->get($name),
54 'domain_id' => $domain,
55 ];
56 }
57 }
58 else {
59 foreach ($settingsBag->all() as $name => $value) {
60 $result[] = [
61 'name' => $name,
62 'value' => $value,
63 'domain_id' => $domain,
64 ];
65 }
66 }
67 foreach ($result as $name => &$setting) {
68 if (isset($setting['value']) && !empty($meta[$name]['serialize'])) {
69 $setting['value'] = \CRM_Core_DAO::unSerializeField($setting['value'], $meta[$name]['serialize']);
70 }
71 }
72 }
73
74}