1 <?php
2
3 namespace Scaffolder\Compilers\Core\Api;
4
5 use Illuminate\Support\Facades\File;
6 use Scaffolder\Compilers\Core\RouteCompiler;
7 use Scaffolder\Support\FileToCompile;
8 use stdClass;
9
10 class ApiRouteCompiler extends RouteCompiler
11 {
12 13 14 15 16 17 18 19 20 21 22 23 24
25 public function compile($stub, $modelName, $modelData, stdClass $scaffolderConfig, $hash, array $extensions, $extra = null)
26 {
27 $this->stub = $stub;
28
29 $this->replaceResource($modelName);
30
31 return $this->stub;
32 }
33
34 35 36 37 38 39 40 41 42
43 public function compileGroup($stub, $compiledRoutes, stdClass $scaffolderConfig)
44 {
45 $this->stub = $stub;
46
47 $this->replaceRoutes($compiledRoutes)
48 ->store(null, $scaffolderConfig, $this->stub, new FileToCompile(null, null));
49
50 return $this->stub;
51 }
52
53 54 55 56 57 58 59 60 61 62
63 protected function store($modelName, stdClass $scaffolderConfig, $compiled, FileToCompile $fileToCompile)
64 {
65 File::append(base_path('../' . strtolower(str_replace(' ', '-', $scaffolderConfig->name . '-api'))) . '/app/Http/routes.php', PHP_EOL . $compiled);
66 }
67 }
68