|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace kalanis\kw_routed_paths; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* Class Support |
|
8
|
|
|
* @package kalanis\kw_routed_paths |
|
9
|
|
|
* Basic class with supporting methods |
|
10
|
|
|
*/ |
|
11
|
|
|
class Support |
|
12
|
|
|
{ |
|
13
|
|
|
public const PREFIX_MOD_NORMAL = 'm'; # show in normal mode |
|
14
|
|
|
public const PREFIX_MOD_SINGLE = 'ms'; # show module as single window |
|
15
|
|
|
public const PREFIX_USER = 'u'; # this is about that user |
|
16
|
|
|
public const PREFIX_LANG = 'l'; # this is about that language |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @param string $name |
|
20
|
|
|
* @return string[] |
|
21
|
|
|
*/ |
|
22
|
12 |
|
public static function moduleNameFromRequest(string $name): array |
|
23
|
|
|
{ |
|
24
|
12 |
|
return array_map( |
|
25
|
12 |
|
'ucfirst', |
|
26
|
12 |
|
array_map( |
|
27
|
12 |
|
[self::class, 'normalizeModuleName'], |
|
28
|
12 |
|
array_map( |
|
29
|
12 |
|
'strtolower', |
|
30
|
12 |
|
explode('--', $name) |
|
31
|
|
|
) |
|
32
|
|
|
) |
|
33
|
|
|
); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
12 |
|
public static function normalizeModuleName(string $moduleName): string |
|
37
|
|
|
{ |
|
38
|
12 |
|
return implode('', array_map([self::class, 'moduleNamePart'], explode('-', $moduleName))); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
12 |
|
public static function moduleNamePart(string $moduleName): string |
|
42
|
|
|
{ |
|
43
|
12 |
|
return ucfirst(strtolower($moduleName)); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param string[] $path |
|
48
|
|
|
* @return string |
|
49
|
|
|
*/ |
|
50
|
18 |
|
public static function requestFromModuleName(array $path): string |
|
51
|
|
|
{ |
|
52
|
18 |
|
return implode('--', array_filter(array_map( |
|
53
|
18 |
|
[self::class, 'linkModuleName'], |
|
54
|
|
|
$path |
|
55
|
|
|
))); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
18 |
|
public static function linkModuleName(string $moduleName): string |
|
59
|
|
|
{ |
|
60
|
18 |
|
if (false != preg_match_all('#([A-Z][a-z0-9]*)#u', $moduleName, $matches)) { |
|
|
|
|
|
|
61
|
17 |
|
return implode('-', array_map('mb_strtolower', $matches[1])); |
|
62
|
|
|
} else { |
|
63
|
1 |
|
return mb_strtolower($moduleName); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
20 |
|
public static function prefixWithSeparator(string $prefix): string |
|
68
|
|
|
{ |
|
69
|
20 |
|
return $prefix . ':'; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|