1
|
|
|
<?php namespace Mascame\Artificer; |
2
|
|
|
|
3
|
|
|
use App; |
4
|
|
|
use Mascame\Artificer\Http\Controllers\BaseController; |
5
|
|
|
use Mascame\Artificer\Http\Controllers\BaseModelController; |
6
|
|
|
use Mascame\Artificer\Extension\PluginManager; |
7
|
|
|
use Mascame\Artificer\Model\Model; |
8
|
|
|
|
9
|
|
|
class Artificer |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
public static $booted = false; |
13
|
|
|
|
14
|
|
|
public static function isBooted() { |
15
|
|
|
return self::$booted; |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Returns the current user's action. |
20
|
|
|
* |
21
|
|
|
* @return null|string |
22
|
|
|
*/ |
23
|
|
|
public static function getCurrentAction() |
24
|
|
|
{ |
25
|
|
|
switch (\Route::currentRouteName()) { |
26
|
|
|
case 'admin.model.create': |
27
|
|
|
return 'create'; |
28
|
|
|
case 'admin.model.edit': |
29
|
|
|
return 'edit'; |
30
|
|
|
case 'admin.model.show': |
31
|
|
|
return 'show'; |
32
|
|
|
case 'admin.model.all': |
33
|
|
|
return 'list'; |
34
|
|
|
default: |
35
|
|
|
return null; |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return Model |
41
|
|
|
*/ |
42
|
|
|
public static function getModel() |
43
|
|
|
{ |
44
|
|
|
return App::make('ArtificerModel'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public static function assets() |
48
|
|
|
{ |
49
|
|
|
return BaseController::assets(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public static function getCurrentModelId($items) |
53
|
|
|
{ |
54
|
|
|
return BaseModelController::getCurrentModelId($items); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param $t |
59
|
|
|
* @return bool |
60
|
|
|
*/ |
61
|
|
|
public static function isClosure($t) |
62
|
|
|
{ |
63
|
|
|
return is_object($t) && ($t instanceof \Closure); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return PluginManager |
68
|
|
|
*/ |
69
|
|
|
public static function pluginManager() |
70
|
|
|
{ |
71
|
|
|
return App::make('ArtificerPluginManager'); |
72
|
|
|
} |
73
|
|
|
/** |
74
|
|
|
* @param $plugin |
75
|
|
|
* @return mixed |
76
|
|
|
*/ |
77
|
|
|
public static function getPlugin($plugin) |
78
|
|
|
{ |
79
|
|
|
return with(App::make('ArtificerPluginManager'))->make($plugin); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
// Todo is it used anywhere? |
83
|
|
|
// public static function store($filepath = null, $content, $overide = false) |
84
|
|
|
// { |
85
|
|
|
// if (!$filepath) { |
86
|
|
|
// $pathinfo = pathinfo($filepath); |
87
|
|
|
// $filepath = $pathinfo['dirname']; |
88
|
|
|
// } |
89
|
|
|
// |
90
|
|
|
// $path = explode('/', $filepath); |
91
|
|
|
// array_pop($path); |
92
|
|
|
// $path = join('/', $path); |
93
|
|
|
// |
94
|
|
|
// if (!file_exists($path)) { |
95
|
|
|
// \File::makeDirectory($path, 0777, true, true); |
96
|
|
|
// } |
97
|
|
|
// |
98
|
|
|
// if (!file_exists($filepath) || $overide) { |
99
|
|
|
// return \File::put($filepath, $content); |
100
|
|
|
// } |
101
|
|
|
// |
102
|
|
|
// return false; |
103
|
|
|
// } |
104
|
|
|
} |