[NFC] Remove some more of the old cvs blocks
[civicrm-core.git] / Civi / Api4 / Action / Setting / Set.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
19b53e5b
C
13namespace Civi\Api4\Action\Setting;
14
15use Civi\Api4\Generic\Result;
16
17/**
18 * Set the value of one or more CiviCRM settings.
19 *
20 * @method array getValues
21 * @method $this setValues(array $value)
19b53e5b
C
22 */
23class Set extends AbstractSettingAction {
24
25 /**
26 * Setting names/values to set.
27 *
28 * @var mixed
29 * @required
30 */
31 protected $values = [];
32
33 /**
34 * @param \Civi\Api4\Generic\Result $result
35 * @param \Civi\Core\SettingsBag $settingsBag
36 * @param array $meta
37 * @param int $domain
38 * @throws \Exception
39 */
40 protected function processSettings(Result $result, $settingsBag, $meta, $domain) {
41 foreach ($this->values as $name => $value) {
42 if (isset($value) && !empty($meta[$name]['serialize'])) {
43 $value = \CRM_Core_DAO::serializeField($value, $meta[$name]['serialize']);
44 }
45 $settingsBag->set($name, $value);
46 $result[] = [
47 'name' => $name,
48 'value' => $this->values[$name],
49 'domain_id' => $domain,
50 ];
51 }
52 }
53
121ec912
CW
54 /**
55 * Add an item to the values array
56 * @param string $settingName
57 * @param mixed $value
58 * @return $this
59 */
60 public function addValue($settingName, $value) {
61 $this->values[$settingName] = $value;
62 return $this;
63 }
64
19b53e5b 65}