Commit | Line | Data |
---|---|---|
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 |
21 | |
22 | namespace Civi\Api4\Generic; | |
23 | ||
24 | /** | |
25 | * Base class for all "Create" api actions. | |
26 | * | |
27 | * @method $this setValues(array $values) Set all field values from an array of key => value pairs. | |
28 | * @method $this addValue($field, $value) Set field value. | |
29 | * @method array getValues() Get field values. | |
30 | * | |
31 | * @package Civi\Api4\Generic | |
32 | */ | |
33 | abstract class AbstractCreateAction extends AbstractAction { | |
34 | ||
35 | /** | |
36 | * Field values to set | |
37 | * | |
38 | * @var array | |
39 | */ | |
40 | protected $values = []; | |
41 | ||
42 | /** | |
43 | * @param string $key | |
44 | * | |
45 | * @return mixed|null | |
46 | */ | |
47 | public function getValue($key) { | |
48 | return isset($this->values[$key]) ? $this->values[$key] : NULL; | |
49 | } | |
50 | ||
51 | /** | |
52 | * @throws \API_Exception | |
53 | */ | |
54 | protected function validateValues() { | |
55 | $unmatched = $this->checkRequiredFields($this->getValues()); | |
56 | if ($unmatched) { | |
57 | throw new \API_Exception("Mandatory values missing from Api4 {$this->getEntityName()}::{$this->getActionName()}: " . implode(", ", $unmatched), "mandatory_missing", ["fields" => $unmatched]); | |
58 | } | |
59 | } | |
60 | ||
61 | } |