forked from ProcessMaker/processmaker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptions.php
More file actions
69 lines (59 loc) · 1.88 KB
/
Options.php
File metadata and controls
69 lines (59 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
namespace ProcessMaker\ImportExport;
use Illuminate\Support\Arr;
use ProcessMaker\Exception\InvalidImportOption;
class Options
{
const IMPORT_OPTIONS = [
'mode' => [
'enum' => [
'update' => 'Update the existing asset with the one being imported',
'discard' => 'Keep the existing asset and discard the one being imported',
'copy' => 'Create a new asset and link dependent assets (in this import) to it',
],
'default' => 'update',
],
'isTemplate' => [
'enum' => [
true => 'Asset is part of a template',
false => 'Asset is not part of a template',
],
'default' => false,
],
'saveAssetsMode' => [
'enum' => [
'saveModelOnly' => 'Save only the model',
'saveAllAssets' => 'Save all assets',
],
'default' => 'saveAllAssets',
],
];
public $options;
public function __construct(array $options)
{
$this->options = $options;
}
public function get($name, $uuid)
{
$optionsForUuid = Arr::get($this->options, $uuid, []);
$default = Arr::get(self::IMPORT_OPTIONS, $name . '.default', null);
if ($default === null) {
throw new InvalidImportOption($name);
}
if (Arr::has($optionsForUuid, $name)) {
return Arr::get($optionsForUuid, $name, $default);
}
/**
* Support for passing in global options like:
*
* new Options([
* 'mode' => 'update',
* 'saveAssetsMode' => 'saveModelOnly',
* 'isTemplate' => false,
* ]);
*
* Note that this is not the usual uuid => options map
*/
return Arr::get($this->options, $name, $default);
}
}