1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sco\Admin\Config; |
4
|
|
|
|
5
|
|
|
use Illuminate\Foundation\Application; |
6
|
|
|
use Sco\Attributes\HasOriginalAndAttributesTrait; |
7
|
|
|
|
8
|
|
|
abstract class Config |
9
|
|
|
{ |
10
|
|
|
use HasOriginalAndAttributesTrait; |
11
|
|
|
|
12
|
|
|
protected $app; |
13
|
|
|
protected $name; |
14
|
|
|
protected $config; |
15
|
|
|
|
16
|
|
|
protected $defaultPermissions = [ |
17
|
|
|
'view' => true, |
18
|
|
|
'create' => true, |
19
|
|
|
'update' => true, |
20
|
|
|
'delete' => true, |
21
|
|
|
]; |
22
|
|
|
|
23
|
|
|
public function __construct(Application $app, $name) |
24
|
|
|
{ |
25
|
|
|
$this->app = $app; |
26
|
|
|
$this->name = $name; |
27
|
|
|
|
28
|
|
|
$this->config = $this->compileConfig(); |
|
|
|
|
29
|
|
|
//$this->setOriginal($attributes); |
|
|
|
|
30
|
|
|
$this->getOptions(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
protected function compileConfig() |
34
|
|
|
{ |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
protected function getTitle() |
38
|
|
|
{ |
39
|
|
|
$title = $this->getAttribute('title'); |
40
|
|
|
if ($title) { |
41
|
|
|
return $title; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
$title = $this->getOriginal('title'); |
45
|
|
|
$this->setAttribute('title', $title); |
46
|
|
|
return $title; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
protected function getPermissions() |
50
|
|
|
{ |
51
|
|
|
$permissions = $this->getAttribute('permissions', collect()); |
52
|
|
|
if ($permissions->isEmpty()) { |
53
|
|
|
$option = $this->getOriginal('permissions'); |
54
|
|
|
if (is_array($option)) { |
55
|
|
|
$option = array_merge($this->defaultPermissions, $option); |
56
|
|
|
foreach ($option as $key => $item) { |
57
|
|
|
$val = $item instanceof \Closure ? $item() : $item; |
58
|
|
|
$permissions->put($key, $val ? true : false); |
59
|
|
|
} |
60
|
|
|
} else { |
61
|
|
|
$val = $option instanceof \Closure ? $option() : $option; |
62
|
|
|
foreach ($this->defaultPermissions as $key => $item) { |
63
|
|
|
$permissions->put($key, $val ? true : false); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
$this->setAttribute('permissions', $permissions); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return $permissions; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
View Code Duplication |
protected function getColumns() |
|
|
|
|
73
|
|
|
{ |
74
|
|
|
$columns = $this->getAttribute('columns', collect()); |
75
|
|
|
if ($columns->isEmpty()) { |
76
|
|
|
$options = $this->getOriginal('columns'); |
77
|
|
|
foreach ($options as $option) { |
78
|
|
|
$columns->push(app('admin.column')->make($option)); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
$this->setAttribute('columns', $columns); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return $columns; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
View Code Duplication |
protected function getFields() |
|
|
|
|
88
|
|
|
{ |
89
|
|
|
$fields = $this->getAttribute('fields', collect()); |
90
|
|
|
if ($fields->isEmpty()) { |
91
|
|
|
$options = $this->getOriginal('fields'); |
92
|
|
|
|
93
|
|
|
foreach ($options as $option) { |
94
|
|
|
$fields->push($option); |
95
|
|
|
} |
96
|
|
|
$this->setAttribute('columns', $fields); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
return $fields; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function getOptions() |
103
|
|
|
{ |
104
|
|
|
$this->getTitle(); |
105
|
|
|
$this->getPermissions(); |
106
|
|
|
//$this->getColumns(); |
|
|
|
|
107
|
|
|
|
108
|
|
|
return $this->getAttributes(); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function __toString() |
112
|
|
|
{ |
113
|
|
|
return $this->toJson(); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.