-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathConfigurationer.php
124 lines (95 loc) · 2.79 KB
/
Configurationer.php
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
namespace App\Containers\Larabeans\Configurationer;
use Illuminate\Support\Traits\Macroable;
use Illuminate\Support\Arr;
class Configurationer
{
use Macroable;
/** @var bool */
public $initialized = true;
public static function addSystemConfiguration($key, $value)
{
config(['configurationer.entities.system.default.' . $key => $value]);
}
public static function getSystemConfiguration()
{
return self::getDefault('system');
}
/**
* $attr is string, can use dot notation
*/
public static function getSystemConfigurationAttr($attr)
{
return config('configurationer.entities.system.default.'.$attr, []);
}
public static function getEntities($after = null)
{
return config('configurationer.entities', []);
}
public static function getEntityKeys()
{
return array_keys(self::getEntities());
}
public static function addEntity($source, $after = null)
{
$entities = config('configurationer.entities');
if(!empty($after)) {
$offset = (array_search($after, self::getEntityKeys())) + 1 ;
$last = array_splice($entities, $offset);
config(['configurationer.entities' => array_merge($entities, $source, $last)]);
} else {
config(['configurationer.entities' => array_merge($entities, $source)]);
}
}
public static function exists($type)
{
return Arr::exists(self::getEntities(), $type);
}
public static function getEntity($key)
{
return config('configurationer.entities.' . $key, false);
}
public static function getModel($key)
{
if($entity = self::getEntity($key))
return $entity['model'];
return false;
}
public static function getTask($key, $type)
{
if($entity = self::getEntity($key)){
if($task = $entity['tasks'][strtolower($type)]) {
return $task;
}
}
return false;
}
public static function getEntityAuthenticateAttr($key)
{
if($entity = self::getEntity($key)){
return $entity['authenticate'];
}
return true;
}
public static function loadInDefaultTask($key)
{
if($entity = self::getEntity($key)){
return $entity['load_in_default_task'];
}
return true;
}
public static function getDefault($key)
{
if($entity = self::getEntity($key))
return config('configurationer.entities'.$entity.'default'); //$entity['default];
return [];
}
public static function format($data, $type = null)
{
if(is_array($data)) {
return $data;
} else {
return json_decode($data);
}
}
}