1
|
|
|
<?php namespace Mascame\Artificer; |
2
|
|
|
|
3
|
|
|
use App; |
4
|
|
|
use Mascame\Artificer\Extension\WidgetManager; |
5
|
|
|
use Mascame\Artificer\Http\Controllers\BaseController; |
6
|
|
|
use Mascame\Artificer\Http\Controllers\BaseModelController; |
7
|
|
|
use Mascame\Artificer\Extension\PluginManager; |
8
|
|
|
use Mascame\Artificer\Model\Model; |
9
|
|
|
|
10
|
|
|
class Artificer |
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Returns the current user's action. |
15
|
|
|
* |
16
|
|
|
* @return null|string |
17
|
|
|
*/ |
18
|
|
|
public static function getCurrentAction() |
19
|
|
|
{ |
20
|
|
|
switch (\Route::currentRouteName()) { |
21
|
|
|
case 'admin.model.create': |
22
|
|
|
return 'create'; |
23
|
|
|
case 'admin.model.edit': |
24
|
|
|
return 'edit'; |
25
|
|
|
case 'admin.model.show': |
26
|
|
|
return 'show'; |
27
|
|
|
case 'admin.model.all': |
28
|
|
|
case 'admin.model.filter': |
29
|
|
|
return 'list'; |
30
|
|
|
default: |
31
|
|
|
return null; |
32
|
|
|
} |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @return Model |
37
|
|
|
*/ |
38
|
|
|
public static function getModel() |
39
|
|
|
{ |
40
|
|
|
return App::make('ArtificerModel'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public static function assets() |
44
|
|
|
{ |
45
|
|
|
return BaseController::assets(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public static function getCurrentModelId($items) |
49
|
|
|
{ |
50
|
|
|
return BaseModelController::getCurrentModelId($items); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param $t |
55
|
|
|
* @return bool |
56
|
|
|
*/ |
57
|
|
|
public static function isClosure($t) |
58
|
|
|
{ |
59
|
|
|
return is_object($t) && ($t instanceof \Closure); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @return PluginManager |
64
|
|
|
*/ |
65
|
|
|
public static function pluginManager() |
66
|
|
|
{ |
67
|
|
|
return App::make('ArtificerPluginManager'); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return WidgetManager |
72
|
|
|
*/ |
73
|
|
|
public static function widgetManager() |
74
|
|
|
{ |
75
|
|
|
return App::make('ArtificerWidgetManager'); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public static function addMenu($options) |
79
|
|
|
{ |
80
|
|
|
return config(['admin.menu' => array_merge(self::getMenu(), [$options])]); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public static function getMenu() |
84
|
|
|
{ |
85
|
|
|
return config('admin.menu'); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public static function getProviders() |
89
|
|
|
{ |
90
|
|
|
return config('admin.providers'); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Use it only for third party Service Providers |
95
|
|
|
* (Your main Service provider must be already declared for this to work) |
96
|
|
|
* |
97
|
|
|
* @param $provider |
98
|
|
|
* @return mixed |
99
|
|
|
*/ |
100
|
|
|
public static function addServiceProvider($provider) |
101
|
|
|
{ |
102
|
|
|
return config(['admin.providers' => array_merge(self::getProviders(), [$provider])]); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @param $plugin |
108
|
|
|
* @return mixed |
109
|
|
|
*/ |
110
|
|
|
// public static function getPlugin($plugin) |
111
|
|
|
// { |
112
|
|
|
// return with(App::make('ArtificerPluginManager'))->make($plugin); |
113
|
|
|
// } |
114
|
|
|
|
115
|
|
|
// Todo is it used anywhere? |
116
|
|
|
// public static function store($filepath = null, $content, $overide = false) |
117
|
|
|
// { |
118
|
|
|
// if (!$filepath) { |
119
|
|
|
// $pathinfo = pathinfo($filepath); |
120
|
|
|
// $filepath = $pathinfo['dirname']; |
121
|
|
|
// } |
122
|
|
|
// |
123
|
|
|
// $path = explode('/', $filepath); |
124
|
|
|
// array_pop($path); |
125
|
|
|
// $path = join('/', $path); |
126
|
|
|
// |
127
|
|
|
// if (!file_exists($path)) { |
128
|
|
|
// \File::makeDirectory($path, 0777, true, true); |
129
|
|
|
// } |
130
|
|
|
// |
131
|
|
|
// if (!file_exists($filepath) || $overide) { |
132
|
|
|
// return \File::put($filepath, $content); |
133
|
|
|
// } |
134
|
|
|
// |
135
|
|
|
// return false; |
136
|
|
|
// } |
137
|
|
|
} |