|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Epesi\Core\System\Integration\Modules\Concerns; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Str; |
|
6
|
|
|
|
|
7
|
|
|
trait HasModule |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* Default module view class |
|
11
|
|
|
* |
|
12
|
|
|
* @param string $alias |
|
13
|
|
|
* @return string |
|
14
|
|
|
*/ |
|
15
|
|
|
final public static function view($alias = null) |
|
16
|
|
|
{ |
|
17
|
|
|
$class = self::namespace() . '\\' . ($alias? Str::studly($alias): self::name()) . 'View'; |
|
18
|
|
|
|
|
19
|
|
|
if ($alias) return $class; |
|
20
|
|
|
|
|
21
|
|
|
return static::$view?: $class; |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Module alias |
|
26
|
|
|
* |
|
27
|
|
|
* @return string |
|
28
|
|
|
*/ |
|
29
|
|
|
final public static function alias() |
|
30
|
|
|
{ |
|
31
|
|
|
if (is_a(static::class, \Epesi\Core\System\Integration\Modules\ModuleCore::class, true) && empty(static::$alias)) { |
|
32
|
|
|
throw new \Exception('Undefined alias in module core class ' . static::class); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
return static::$alias?? static::module()::alias(); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Module core class name |
|
40
|
|
|
* |
|
41
|
|
|
* @return string |
|
42
|
|
|
*/ |
|
43
|
|
|
public static function module() |
|
44
|
|
|
{ |
|
45
|
|
|
return static::namespace() . '\\' . static::name() . 'Core'; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Namespace of the module |
|
50
|
|
|
* |
|
51
|
|
|
* @return string |
|
52
|
|
|
*/ |
|
53
|
|
|
final public static function namespace() |
|
54
|
|
|
{ |
|
55
|
|
|
return join('\\', array_slice(explode('\\', static::class), 0, -1)); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Base name of the module |
|
60
|
|
|
* |
|
61
|
|
|
* @return string |
|
62
|
|
|
*/ |
|
63
|
|
|
final public static function name() |
|
64
|
|
|
{ |
|
65
|
|
|
$names = array_slice(explode('\\', static::class), -2, -1); |
|
66
|
|
|
|
|
67
|
|
|
return $names? reset($names): ''; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Path to the module directory. |
|
72
|
|
|
* |
|
73
|
|
|
* @return string path to the module directory |
|
74
|
|
|
*/ |
|
75
|
|
|
final public static function path() { |
|
76
|
|
|
$reflection = new \ReflectionClass(static::class); |
|
77
|
|
|
|
|
78
|
|
|
return pathinfo($reflection->getFileName(), PATHINFO_DIRNAME); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Path to the module directory from installation base directory. |
|
83
|
|
|
* |
|
84
|
|
|
* @return string path to the module directory |
|
85
|
|
|
*/ |
|
86
|
|
|
final public static function relativePath() { |
|
87
|
|
|
return str_ireplace(base_path() . DIRECTORY_SEPARATOR, '', static::path()); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|