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
|
|
|
public function getConsoleOutput() { |
18
|
|
|
return 'Generated controller: '.$this->command->naming[$this->key]->getRelativeFilePath(); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
protected function buildFileContent() |
22
|
|
|
{ |
23
|
|
|
$this->replaceClassNamespace(); |
24
|
|
|
$this->replaceClassName(); |
25
|
|
|
$this->replaceModelRelatedStrings(); |
26
|
|
|
$this->replaceRequestRelatedStrings(); |
27
|
|
|
$this->replaceLanguageFileRelatedStrings(); |
28
|
|
|
$this->replaceRouteFileRelatedStrings(); |
29
|
|
|
$this->replaceFieldStrings(); |
30
|
|
|
$this->replaceColumnStrings(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
protected function replaceModelRelatedStrings() |
34
|
|
|
{ |
35
|
|
|
$this->fileContent = str_replace('__model_namespace__', $this->command->naming['crudModel']->getNamespace(), $this->fileContent); |
|
|
|
|
36
|
|
|
$this->fileContent = str_replace('__model_class__', $this->command->naming['crudModel']->getClassName(), $this->fileContent); |
|
|
|
|
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
protected function replaceRequestRelatedStrings() |
40
|
|
|
{ |
41
|
|
|
$this->fileContent = str_replace('__request_namespace__', $this->command->naming['crudRequest']->getNamespace(), $this->fileContent); |
|
|
|
|
42
|
|
|
$this->fileContent = str_replace('__request_class__', $this->command->naming['crudRequest']->getClassName(), $this->fileContent); |
|
|
|
|
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
protected function replaceLanguageFileRelatedStrings() |
46
|
|
|
{ |
47
|
|
|
$this->fileContent = str_replace('__languagefile_key__', $this->command->naming['languageFile']->getName(), $this->fileContent); |
|
|
|
|
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
protected function replaceRouteFileRelatedStrings() |
51
|
|
|
{ |
52
|
|
|
$this->fileContent = str_replace('__route_name__', $this->command->naming['routeFile']->getName(), $this->fileContent); |
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
protected function replaceFieldStrings() |
56
|
|
|
{ |
57
|
|
|
$this->fileContent = str_replace('__fields__', ShortSyntaxArray::parse($this->command->schema->getCrudFields()->toArray()), $this->fileContent); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
protected function replaceColumnStrings() |
61
|
|
|
{ |
62
|
|
|
$this->fileContent = str_replace('__columns__', ShortSyntaxArray::parse($this->command->schema->getCrudColumns()->toArray()), $this->fileContent); |
|
|
|
|
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
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.