Scaffolder v2.0.0
  • Namespace
  • Class

Namespaces

  • Scaffolder
    • Commands
    • Compilers
      • Core
        • Api
      • Layout
      • View

Classes

  • Scaffolder\Commands\BaseCommand
  • Scaffolder\Commands\ClearCacheCommand
  • Scaffolder\Commands\GeneratorCommand
  • Scaffolder\Commands\InitializeApiCommand
  • Scaffolder\Compilers\AbstractCompiler
  • Scaffolder\Compilers\AbstractCoreCompiler
  • Scaffolder\Compilers\AbstractViewCompiler
  • Scaffolder\Compilers\Core\Api\ApiControllerCompiler
  • Scaffolder\Compilers\Core\Api\ApiModelCompiler
  • Scaffolder\Compilers\Core\Api\ApiRouteCompiler
  • Scaffolder\Compilers\Core\ControllerCompiler
  • Scaffolder\Compilers\Core\MigrationCompiler
  • Scaffolder\Compilers\Core\ModelCompiler
  • Scaffolder\Compilers\Core\RouteCompiler
  • Scaffolder\Compilers\Layout\CreateLayoutCompiler
  • Scaffolder\Compilers\Layout\EditLayoutCompiler
  • Scaffolder\Compilers\Layout\PageLayoutCompiler
  • Scaffolder\Compilers\View\CreateViewCompiler
  • Scaffolder\Compilers\View\DashboardViewCompiler
  • Scaffolder\Compilers\View\EditViewCompiler
  • Scaffolder\Compilers\View\IndexViewCompiler
  • Scaffolder\Compilers\View\LoginViewCompiler
  • Scaffolder\Compilers\View\WelcomeViewCompiler
  • Scaffolder\ScaffolderServiceProvider
  1 <?php
  2 
  3 namespace Scaffolder\Compilers\Core;
  4 
  5 use Illuminate\Support\Facades\File;
  6 use Scaffolder\Compilers\AbstractCoreCompiler;
  7 use Scaffolder\Support\FileToCompile;
  8 use Scaffolder\Support\PathParser;
  9 use stdClass;
 10 
 11 class RouteCompiler extends AbstractCoreCompiler
 12 {
 13     /**
 14      * Compiles a route.
 15      *
 16      * @param $stub
 17      * @param $modelName
 18      * @param $modelData
 19      * @param \stdClass $scaffolderConfig
 20      * @param $hash
 21      * @param \Scaffolder\Support\Contracts\ScaffolderExtensionInterface[] $extensions
 22      * @param null $extra
 23      *
 24      * @return string
 25      */
 26     public function compile($stub, $modelName, $modelData, stdClass $scaffolderConfig, $hash, array $extensions, $extra = null)
 27     {
 28         $this->stub = $stub;
 29 
 30         $this->replaceResource($modelName);
 31 
 32         return $this->stub;
 33     }
 34 
 35     /**
 36      * Compiles a group of routes.
 37      *
 38      * @param $stub
 39      * @param $compiledRoutes
 40      * @param \stdClass $scaffolderConfig
 41      *
 42      * @return string
 43      */
 44     public function compileGroup($stub, $compiledRoutes, stdClass $scaffolderConfig)
 45     {
 46         $this->stub = $stub;
 47 
 48         $this->replaceRoutes($compiledRoutes)
 49             ->replacePrefix($scaffolderConfig->routing->prefix)
 50             ->store(null, $scaffolderConfig, $this->stub, new FileToCompile(null, null));
 51 
 52         return $this->stub;
 53     }
 54 
 55     /**
 56      * Store the compiled stub.
 57      *
 58      * @param $modelName
 59      * @param \stdClass $scaffolderConfig
 60      * @param $compiled
 61      * @param \Scaffolder\Support\FileToCompile $fileToCompile
 62      *
 63      * @return mixed|void
 64      */
 65     protected function store($modelName, stdClass $scaffolderConfig, $compiled, FileToCompile $fileToCompile)
 66     {
 67         File::append(PathParser::parse($scaffolderConfig->paths->routes), PHP_EOL . $compiled);
 68     }
 69 
 70     /**
 71      * Replace the resource.
 72      *
 73      * @param $modelName
 74      *
 75      * @return $this
 76      */
 77     protected function replaceResource($modelName)
 78     {
 79         $this->stub = str_replace('{{resource_lw}}', strtolower($modelName), $this->stub);
 80         $this->stub = str_replace('{{resource}}', $modelName, $this->stub);
 81 
 82         return $this;
 83     }
 84 
 85     /**
 86      * Replace compiled routes.
 87      *
 88      * @param $compiledRoutes
 89      *
 90      * @return $this
 91      */
 92     protected function replaceRoutes($compiledRoutes)
 93     {
 94         $this->stub = str_replace('{{routes}}', $compiledRoutes, $this->stub);
 95 
 96         return $this;
 97     }
 98 
 99     /**
100      * Replace the prefix.
101      *
102      * @param $prefix
103      *
104      * @return $this
105      */
106     private function replacePrefix($prefix)
107     {
108         $this->stub = str_replace('{{route_prefix}}', $prefix, $this->stub);
109 
110         return $this;
111     }
112 }
113 
Scaffolder v2.0.0 API documentation generated by ApiGen