|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Terranet\Administrator; |
|
4
|
|
|
|
|
5
|
|
|
use BenSampo\Enum\Traits\CastsEnums; |
|
|
|
|
|
|
6
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
|
|
|
|
|
7
|
|
|
use Illuminate\Support\Arr; |
|
8
|
|
|
use Illuminate\Support\Str; |
|
9
|
|
|
use Terranet\Administrator\Services\Template; |
|
10
|
|
|
use Zend\Code\Reflection\ClassReflection; |
|
11
|
|
|
|
|
12
|
|
|
class Architect |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* Get the AdminArchitect URI path. |
|
16
|
|
|
* |
|
17
|
|
|
* @return \Illuminate\Config\Repository|mixed |
|
|
|
|
|
|
18
|
|
|
*/ |
|
19
|
|
|
public static function path() |
|
20
|
|
|
{ |
|
21
|
|
|
return config('administrator.prefix', 'cms'); |
|
|
|
|
|
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Finds first module which uses a model. |
|
26
|
|
|
* |
|
27
|
|
|
* @param Model|string $model |
|
28
|
|
|
* @param string $urlKey |
|
29
|
|
|
* @return mixed |
|
30
|
|
|
*/ |
|
31
|
|
|
public static function resourceByEntity($model, string $urlKey = null) |
|
32
|
|
|
{ |
|
33
|
|
|
return app('scaffold.modules')->first(function ($module) use ($model, $urlKey) { |
|
|
|
|
|
|
34
|
|
|
$urlEquals = $urlKey ? $module->url() === $urlKey : true; |
|
35
|
|
|
|
|
36
|
|
|
if (\is_string($model)) { |
|
37
|
|
|
return \get_class($module->model()) === $model && $urlEquals; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
return \get_class($module->model()) === \get_class($model) && $urlEquals; |
|
41
|
|
|
}); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Finds resource by a key. |
|
46
|
|
|
* |
|
47
|
|
|
* @param string $url |
|
48
|
|
|
* @return mixed |
|
49
|
|
|
*/ |
|
50
|
|
|
public static function resourceForKey(string $url) |
|
51
|
|
|
{ |
|
52
|
|
|
return app('scaffold.modules')->first(function ($module) use ($url) { |
|
|
|
|
|
|
53
|
|
|
return $module->url() === $url; |
|
54
|
|
|
}); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Humanize the given value into a proper name. |
|
59
|
|
|
* |
|
60
|
|
|
* @param string $value |
|
61
|
|
|
* @return string |
|
62
|
|
|
*/ |
|
63
|
|
|
public static function humanize($value) |
|
64
|
|
|
{ |
|
65
|
|
|
if (\is_object($value)) { |
|
|
|
|
|
|
66
|
|
|
return static::humanize(class_basename(\get_class($value))); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
return str_replace('_', ' ', Str::title(Str::snake($value, ' '))); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @return ArchitectRoutes |
|
74
|
|
|
*/ |
|
75
|
|
|
public static function routes() |
|
76
|
|
|
{ |
|
77
|
|
|
return new ArchitectRoutes(); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Ensure the column is of type Enum. |
|
82
|
|
|
* |
|
83
|
|
|
* @param Model $model |
|
84
|
|
|
* @param string $column |
|
85
|
|
|
* @return bool |
|
86
|
|
|
*/ |
|
87
|
|
|
public static function castedEnumType(Model $model, string $column) |
|
88
|
|
|
{ |
|
89
|
|
|
return Arr::has(class_uses($model), CastsEnums::class) && $model->hasEnumCast($column); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Extract values from Casted Enum type. |
|
94
|
|
|
* |
|
95
|
|
|
* @param Model $model |
|
96
|
|
|
* @param string $column |
|
97
|
|
|
* @param bool $nullable |
|
98
|
|
|
* @return array |
|
99
|
|
|
* @throws \ReflectionException |
|
100
|
|
|
*/ |
|
101
|
|
|
public static function castedEnumValues(Model $model, string $column, bool $nullable = false) |
|
102
|
|
|
{ |
|
103
|
|
|
$reflection = new ClassReflection($model); |
|
104
|
|
|
|
|
105
|
|
|
$property = tap($reflection->getProperty('enumCasts'))->setAccessible(true); |
|
106
|
|
|
|
|
107
|
|
|
$enum = $property->getValue(new $model)[$column]; |
|
108
|
|
|
|
|
109
|
|
|
$values = $enum::toSelectArray(); |
|
110
|
|
|
if ($nullable) { |
|
111
|
|
|
$values = ['' => '----'] + $values; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
return $values; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
public static function template() |
|
118
|
|
|
{ |
|
119
|
|
|
return new Template(); |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths