|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Webfactor\Laravel\Generators\Services; |
|
4
|
|
|
|
|
5
|
|
|
use Webfactor\Laravel\Generators\Contracts\SchemaFieldAbstract; |
|
6
|
|
|
use Webfactor\Laravel\Generators\Contracts\ServiceAbstract; |
|
7
|
|
|
use Webfactor\Laravel\Generators\Contracts\ServiceInterface; |
|
8
|
|
|
use Webfactor\Laravel\Generators\Helper\ShortSyntaxArray; |
|
9
|
|
|
use Webfactor\Laravel\Generators\Traits\CanGenerateFile; |
|
10
|
|
|
|
|
11
|
|
|
class BackpackCrudControllerService extends ServiceAbstract implements ServiceInterface |
|
12
|
|
|
{ |
|
13
|
|
|
use CanGenerateFile; |
|
14
|
|
|
|
|
15
|
|
|
protected $key = 'crudController'; |
|
16
|
|
|
|
|
17
|
|
|
protected function buildFileContent() |
|
18
|
|
|
{ |
|
19
|
|
|
$this->replaceClassNamespace(); |
|
20
|
|
|
$this->replaceClassName(); |
|
21
|
|
|
$this->replaceModelRelatedStrings(); |
|
22
|
|
|
$this->replaceRequestRelatedStrings(); |
|
23
|
|
|
$this->replaceLanguageFileRelatedStrings(); |
|
24
|
|
|
$this->replaceRouteFileRelatedStrings(); |
|
25
|
|
|
$this->replaceFieldStrings(); |
|
26
|
|
|
$this->replaceColumnStrings(); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
protected function replaceModelRelatedStrings() |
|
30
|
|
|
{ |
|
31
|
|
|
$this->fileContent = str_replace('__model_namespace__', $this->command->naming['crudModel']->getNamespace(), $this->fileContent); |
|
|
|
|
|
|
32
|
|
|
$this->fileContent = str_replace('__model_class__', $this->command->naming['crudModel']->getClassName(), $this->fileContent); |
|
|
|
|
|
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
protected function replaceRequestRelatedStrings() |
|
36
|
|
|
{ |
|
37
|
|
|
$this->fileContent = str_replace('__request_namespace__', $this->command->naming['crudRequest']->getNamespace(), $this->fileContent); |
|
|
|
|
|
|
38
|
|
|
$this->fileContent = str_replace('__request_class__', $this->command->naming['crudRequest']->getClassName(), $this->fileContent); |
|
|
|
|
|
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
protected function replaceLanguageFileRelatedStrings() |
|
42
|
|
|
{ |
|
43
|
|
|
$this->fileContent = str_replace('__languagefile_key__', $this->command->naming['languageFile']->getName(), $this->fileContent); |
|
|
|
|
|
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
protected function replaceRouteFileRelatedStrings() |
|
47
|
|
|
{ |
|
48
|
|
|
$this->fileContent = str_replace('__route_name__', $this->command->naming['routeFile']->getName(), $this->fileContent); |
|
|
|
|
|
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
protected function replaceFieldStrings() |
|
52
|
|
|
{ |
|
53
|
|
|
$this->fileContent = str_replace('__fields__', ShortSyntaxArray::parse($this->command->schema->getCrudFields()->toArray()), $this->fileContent); |
|
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
protected function replaceColumnStrings() |
|
57
|
|
|
{ |
|
58
|
|
|
$this->fileContent = str_replace('__columns__', ShortSyntaxArray::parse($this->command->schema->getCrudColumns()->toArray()), $this->fileContent); |
|
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.