|
1
|
|
|
<?php |
|
2
|
|
|
namespace Prateekkarki\Laragen\Generators\Common; |
|
3
|
|
|
|
|
4
|
|
|
use Prateekkarki\Laragen\Models\LaragenOptions; |
|
5
|
|
|
use Prateekkarki\Laragen\Generators\BaseGenerator; |
|
6
|
|
|
use Prateekkarki\Laragen\Generators\GeneratorInterface; |
|
7
|
|
|
|
|
8
|
|
|
class Route extends BaseGenerator implements GeneratorInterface |
|
9
|
|
|
{ |
|
10
|
|
|
protected static $initializeFlag = 0; |
|
11
|
|
|
|
|
12
|
|
|
private static $destination = "routes"; |
|
13
|
|
|
|
|
14
|
|
|
public function generate() |
|
15
|
|
|
{ |
|
16
|
|
|
$generatedFiles = []; |
|
17
|
|
|
|
|
18
|
|
|
$backendAuthRouteFile = $this->getPath(self::$destination."/backend//")."auth.php"; |
|
19
|
|
|
$webRouteFile = $this->getPath(self::$destination."/frontend//")."web.php"; |
|
20
|
|
|
$backendApiRouteFile = $this->getPath(self::$destination."/backend//")."api.php"; |
|
21
|
|
|
$backendWebRouteFile = $this->getPath(self::$destination."/backend//")."web.php"; |
|
22
|
|
|
|
|
23
|
|
|
if (self::$initializeFlag++ == 0) { |
|
24
|
|
|
$this->initializeFiles([ |
|
25
|
|
|
$backendAuthRouteFile => "backend/routes/auth", |
|
26
|
|
|
$backendApiRouteFile => "backend/routes/api", |
|
27
|
|
|
$backendWebRouteFile => "backend/routes/web" |
|
28
|
|
|
]); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
$laragen = LaragenOptions::getInstance(); |
|
32
|
|
|
if ($laragen->generatorExists('Frontend\\Controller')) { |
|
33
|
|
|
$this->insertIntoFile( |
|
34
|
|
|
$webRouteFile, |
|
35
|
|
|
"<?php\n", |
|
36
|
|
|
"use App\\Http\\Controllers\\".$this->module->getModelName()."Controller;\n" |
|
37
|
|
|
); |
|
38
|
|
|
|
|
39
|
|
|
$this->insertIntoFile( |
|
40
|
|
|
$webRouteFile, |
|
41
|
|
|
"/"."* Insert your routes here */", |
|
42
|
|
|
"\n".$this->getTabs(1)."Route::resource('".$this->module->getModuleName()."', ".$this->module->getModelName()."Controller::class);" |
|
43
|
|
|
); |
|
44
|
|
|
$generatedFiles[] = $webRouteFile; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
if ($laragen->generatorExists('Backend\\Controller')) { |
|
48
|
|
|
$this->insertIntoFile( |
|
49
|
|
|
$backendWebRouteFile, |
|
50
|
|
|
"<?php\n", |
|
51
|
|
|
"use App\\Http\\Controllers\\Backend\\".$this->module->getModelName()."Controller;\n" |
|
52
|
|
|
); |
|
53
|
|
|
|
|
54
|
|
|
$this->insertIntoFile( |
|
55
|
|
|
$backendWebRouteFile, |
|
56
|
|
|
"/"."* Insert your routes here */", |
|
57
|
|
|
"\n".$this->getTabs(1)."Route::resource('".$this->module->getModuleName()."', ".$this->module->getModelName()."Controller::class);" |
|
58
|
|
|
); |
|
59
|
|
|
$generatedFiles[] = $backendWebRouteFile; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
if ($laragen->generatorExists('Backend\\Api')) { |
|
63
|
|
|
$this->insertIntoFile( |
|
64
|
|
|
$backendApiRouteFile, |
|
65
|
|
|
"<?php\n", |
|
66
|
|
|
"use App\\Http\\Controllers\\Backend\\Api\\".$this->module->getModelName()."Controller;\n" |
|
67
|
|
|
); |
|
68
|
|
|
|
|
69
|
|
|
$this->insertIntoFile( |
|
70
|
|
|
$backendApiRouteFile, |
|
71
|
|
|
"/"."* Insert your routes here */", |
|
72
|
|
|
"\n".$this->getTabs(1)."Route::resource('".$this->module->getModuleName()."', ".$this->module->getModelName()."Controller::class);" |
|
73
|
|
|
); |
|
74
|
|
|
|
|
75
|
|
|
$generatedFiles[] = $backendApiRouteFile; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
return $generatedFiles; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|