-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathhelper.php
executable file
·107 lines (87 loc) · 2.85 KB
/
helper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
use Symfony\Component\Finder\Finder;
use Idel\Modular\Exceptions\ModuleNotFoundException;
if (!function_exists('modules')) {
/**
* Get modules repository.
*
* @param string $location
* @return \Idel\Modular\RepositoryManager \Idel\Modular\Repository
*/
function modules(string $location = null) {
if ($location) {
return app('modules')->location($location);
}
return app('modules');
}
}
if (!function_exists('module_path')) {
/**
* Return the path to the given module file.
*
* @param string $slug
* @param string $file
* @param string|null $location
* @param boolean $inSrc
* @return string
* @throws \Idel\Modular\Exceptions\ModuleNotFoundException
*/
function module_path($slug = null, $file = '', $location = null , $inSrc = false , $typeSeeder = false) {
$location = $location ?: "modules";
$modulesPath = config('laravel-modules.modulesPath');
$filePath = $file ? '/' . ltrim($file, '/') : '';
if (is_null($slug)) {
if (empty($file)) {
return $modulesPath;
}
return $modulesPath . $filePath;
}
$module = Module::location($location)->where('slug', $slug);
if (is_null($module)) {
throw new ModuleNotFoundException($slug);
}
if ($inSrc) {
return $modulesPath . '/' . $module['basename'] . '/src' . $filePath;
} else if ($typeSeeder) {
return $modulesPath . '/' . $module['basename'] . $filePath;
} else{
return $modulesPath . '/' . $module['basename'] . $filePath;
}
}
}
if (!function_exists('module_class')) {
/**
* Return the full path to the given module class.
*
* @param string $slug
* @param string $class
* @param string $location
* @return string
* @throws \Idel\Modular\Exceptions\ModuleNotFoundException
*/
function module_class($slug, $class, $location = null) {
$location = $location ?: config('laravel-modules.modulesPath');
$module = modules($location)->where('slug', $slug);
if (is_null($module)) {
throw new ModuleNotFoundException($slug);
}
$namespace = "App\\" . $module['name'];
return "$namespace\\$class";
}
}
if (! function_exists('getNovaResources')) {
/**
* Autoload all nova resources of your module.
*
* @return array
*/
function getNovaResources($resourcesPath , $namSpace)
{
$resources = [];
foreach ((new Finder)->in($resourcesPath)->files() as $resource) {
$fileName = str_replace('.php', '', $resource->getFilename());
$resources[] = str_replace('/' , '\\' ,"{$namSpace}/Resources/{$fileName}");
}
return $resources;
}
}