1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nip\Router\RouteFactory; |
4
|
|
|
|
5
|
|
|
use Nip\Router\RouteCollection; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Trait HasModulesRoutesTrait |
9
|
|
|
* @package Nip\Router\RouteFactory |
10
|
|
|
*/ |
11
|
|
|
trait HasModulesRoutesTrait |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @param RouteCollection $collection |
16
|
|
|
* @param $module |
17
|
|
|
* @param $prefix |
18
|
|
|
*/ |
19
|
3 |
|
public static function generateGenericModuleDefaultRoutes($collection, $module, $prefix) |
20
|
|
|
{ |
21
|
3 |
|
$moduleName = is_array($module) ? $module[0] : $module; |
22
|
3 |
|
$params = ['module' => $module]; |
23
|
|
|
|
24
|
3 |
|
self::generateIndexRoute( |
25
|
3 |
|
$collection, |
26
|
3 |
|
$moduleName, |
27
|
3 |
|
self::generateModuleRouteClassBase($module, 'Literal'), |
28
|
3 |
|
$prefix, |
29
|
3 |
|
$params |
30
|
|
|
); |
31
|
|
|
|
32
|
3 |
|
self::generateStandardRoute( |
33
|
3 |
|
$collection, |
34
|
3 |
|
$moduleName . ".default", |
35
|
3 |
|
self::generateModuleRouteClassBase($module, 'Standard'), |
36
|
3 |
|
$prefix, |
37
|
3 |
|
null, |
38
|
3 |
|
$params |
39
|
|
|
); |
40
|
3 |
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param string|array $module |
44
|
|
|
* @param string $type |
45
|
|
|
* @return string |
46
|
|
|
*/ |
47
|
3 |
|
public static function generateModuleRouteClassBase($module, $type) |
48
|
|
|
{ |
49
|
3 |
|
if (is_array($module)) { |
50
|
2 |
|
$namespace = $module[1]; |
51
|
2 |
|
$module = $module[0]; |
52
|
2 |
|
$module = $module == 'default' ? 'frontend' : $module; |
53
|
2 |
|
return $namespace . 'Modules\\' . ucfirst($module) . '\Routes\\' . ucfirst($type) . 'Route'; |
54
|
|
|
} |
55
|
1 |
|
return ucfirst($module) . '_Route_' . ucfirst($type); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param RouteCollection $collection |
60
|
|
|
* @param $class |
61
|
|
|
*/ |
62
|
|
|
public static function generateModuleDefaultErrorRoutes($collection, $class) |
63
|
|
|
{ |
64
|
|
|
self::generateModuleErrorRoutes($collection, $class, 'default'); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param RouteCollection $collection |
69
|
|
|
* @param $class |
70
|
|
|
* @param string $module |
71
|
|
|
*/ |
72
|
|
|
public static function generateModuleErrorRoutes($collection, $class, $module = 'default') |
73
|
|
|
{ |
74
|
|
|
foreach (['403', '404', '500'] as $code) { |
75
|
|
|
self::generateLiteralRoute($collection, $module . ".error." . $code, $class, '', '/' . $code, |
76
|
|
|
["controller" => "error", "action" => "index", "error_type" => $code]); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|