Skip to content

Commit 08307a8

Browse files
authored
Adopt replacement placeholder to laravel syntax (#311)
1 parent 0e93ed4 commit 08307a8

33 files changed

+113
-113
lines changed

src/Generators/ControllerGenerator.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ public function types(): array
7373

7474
protected function populateStub(string $stub, Controller $controller)
7575
{
76-
$stub = str_replace('DummyNamespace', $controller->fullyQualifiedNamespace(), $stub);
77-
$stub = str_replace('DummyClass', $controller->className(), $stub);
78-
$stub = str_replace('// methods...', $this->buildMethods($controller), $stub);
79-
$stub = str_replace('// imports...', $this->buildImports($controller), $stub);
76+
$stub = str_replace('{{ namespace }}', $controller->fullyQualifiedNamespace(), $stub);
77+
$stub = str_replace('{{ class }}', $controller->className(), $stub);
78+
$stub = str_replace('{{ methods }}', $this->buildMethods($controller), $stub);
79+
$stub = str_replace('{{ imports }}', $this->buildImports($controller), $stub);
8080

8181
return $stub;
8282
}
@@ -88,7 +88,7 @@ protected function buildMethods(Controller $controller)
8888
$methods = '';
8989

9090
foreach ($controller->methods() as $name => $statements) {
91-
$method = str_replace('DummyMethod', $name, $template);
91+
$method = str_replace('{{ method }}', $name, $template);
9292

9393
if (in_array($name, ['edit', 'update', 'show', 'destroy'])) {
9494
$context = Str::singular($controller->prefix());
@@ -168,7 +168,7 @@ protected function buildMethods(Controller $controller)
168168
}
169169

170170
if (!empty($body)) {
171-
$method = str_replace('//', trim($body), $method);
171+
$method = str_replace('{{ body }}', trim($body), $method);
172172
}
173173

174174
$methods .= PHP_EOL.$method;

src/Generators/FactoryGenerator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ protected function getPath(Model $model)
6565

6666
protected function populateStub(string $stub, Model $model)
6767
{
68-
$stub = str_replace('DummyClass', $model->name(), $stub);
69-
$stub = str_replace('// definition...', $this->buildDefinition($model), $stub);
70-
$stub = str_replace('// imports...', $this->buildImports($model), $stub);
68+
$stub = str_replace('{{ class }}', $model->name(), $stub);
69+
$stub = str_replace('{{ definition }}', $this->buildDefinition($model), $stub);
70+
$stub = str_replace('{{ imports }}', $this->buildImports($model), $stub);
7171

7272
return $stub;
7373
}

src/Generators/MigrationGenerator.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,18 @@ public function types(): array
8484

8585
protected function populateStub(string $stub, Model $model)
8686
{
87-
$stub = str_replace('DummyClass', $this->getClassName($model), $stub);
88-
$stub = str_replace('DummyTable', $model->tableName(), $stub);
89-
$stub = str_replace('// definition...', $this->buildDefinition($model), $stub);
87+
$stub = str_replace('{{ class }}', $this->getClassName($model), $stub);
88+
$stub = str_replace('{{ table }}', $model->tableName(), $stub);
89+
$stub = str_replace('{{ definition }}', $this->buildDefinition($model), $stub);
9090

9191
return $stub;
9292
}
9393

9494
protected function populatePivotStub(string $stub, array $segments)
9595
{
96-
$stub = str_replace('DummyClass', $this->getPivotClassName($segments), $stub);
97-
$stub = str_replace('DummyTable', $this->getPivotTableName($segments), $stub);
98-
$stub = str_replace('// definition...', $this->buildPivotTableDefinition($segments), $stub);
96+
$stub = str_replace('{{ class }}', $this->getPivotClassName($segments), $stub);
97+
$stub = str_replace('{{ table }}', $this->getPivotTableName($segments), $stub);
98+
$stub = str_replace('{{ definition }}', $this->buildPivotTableDefinition($segments), $stub);
9999

100100
return $stub;
101101
}

src/Generators/ModelGenerator.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ public function types(): array
4848

4949
protected function populateStub(string $stub, Model $model)
5050
{
51-
$stub = str_replace('DummyNamespace', $model->fullyQualifiedNamespace(), $stub);
52-
$stub = str_replace('DummyClass', $model->name(), $stub);
53-
$stub = str_replace('/** DummyPHPDocClass **/', $this->buildClassPhpDoc($model), $stub);
51+
$stub = str_replace('{{ namespace }}', $model->fullyQualifiedNamespace(), $stub);
52+
$stub = str_replace('{{ class }}', $model->name(), $stub);
53+
$stub = str_replace('{{ PHPDoc }}', $this->buildClassPhpDoc($model), $stub);
5454

5555
$body = $this->buildProperties($model);
5656
$body .= PHP_EOL.PHP_EOL;
5757
$body .= $this->buildRelationships($model);
5858

59-
$stub = str_replace('// ...', trim($body), $stub);
59+
$stub = str_replace('{{ body }}', trim($body), $stub);
6060
$stub = $this->addTraits($model, $stub);
6161

6262
return $stub;
@@ -187,10 +187,10 @@ protected function buildRelationships(Model $model)
187187
} elseif (in_array($type, ['hasMany', 'belongsToMany', 'morphMany'])) {
188188
$method_name = Str::plural($column_name);
189189
}
190-
$method = str_replace('DummyName', Str::camel($method_name), $template);
190+
$method = str_replace('{{ method }}', Str::camel($method_name), $template);
191191
$method = str_replace('null', $relationship, $method);
192192

193-
$phpDoc = str_replace('DummyReturn', '\Illuminate\Database\Eloquent\Relations\\'.Str::ucfirst($type), $commentTemplate);
193+
$phpDoc = str_replace('{{ namespacedReturnClass }}', '\Illuminate\Database\Eloquent\Relations\\'.Str::ucfirst($type), $commentTemplate);
194194

195195
$methods .= PHP_EOL.$phpDoc.$method;
196196
}

src/Generators/SeederGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ public function types(): array
4747

4848
protected function populateStub(string $stub, string $model)
4949
{
50-
$stub = str_replace('DummyClass', $this->getClassName($model), $stub);
51-
$stub = str_replace('//', $this->build($model), $stub);
50+
$stub = str_replace('{{ class }}', $this->getClassName($model), $stub);
51+
$stub = str_replace('{{ body }}', $this->build($model), $stub);
5252

5353
return $stub;
5454
}

src/Generators/StatementGenerator.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ protected function buildConstructor($statement)
3030
}
3131

3232
if (empty($statement->data())) {
33-
return trim($constructor);
33+
$stub = (str_replace('{{ body }}', '//', $constructor));
34+
} else {
35+
$stub = $this->buildProperties($statement->data()) . PHP_EOL . PHP_EOL;
36+
$stub .= str_replace('__construct()', '__construct(' . $this->buildParameters($statement->data()) . ')', $constructor);
37+
$stub = str_replace('{{ body }}', $this->buildAssignments($statement->data()), $stub);
3438
}
3539

36-
$stub = $this->buildProperties($statement->data()) . PHP_EOL . PHP_EOL;
37-
$stub .= str_replace('__construct()', '__construct(' . $this->buildParameters($statement->data()) . ')', $constructor);
38-
$stub = trim(str_replace('//', $this->buildAssignments($statement->data()), $stub));
39-
40-
return $stub;
40+
return trim($stub);
4141
}
4242

4343
protected function buildProperties(array $data)

src/Generators/Statements/EventGenerator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ protected function getPath(string $name)
6161

6262
protected function populateStub(string $stub, FireStatement $fireStatement)
6363
{
64-
$stub = str_replace('DummyNamespace', config('blueprint.namespace').'\\Events', $stub);
65-
$stub = str_replace('DummyClass', $fireStatement->event(), $stub);
66-
$stub = str_replace('// properties...', $this->buildConstructor($fireStatement), $stub);
64+
$stub = str_replace('{{ namespace }}', config('blueprint.namespace').'\\Events', $stub);
65+
$stub = str_replace('{{ class }}', $fireStatement->event(), $stub);
66+
$stub = str_replace('{{ properties }}', $this->buildConstructor($fireStatement), $stub);
6767

6868
return $stub;
6969
}

src/Generators/Statements/FormRequestGenerator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ protected function getPath(Controller $controller, string $name)
7777

7878
protected function populateStub(string $stub, string $name, $context, ValidateStatement $validateStatement, Controller $controller)
7979
{
80-
$stub = str_replace('DummyNamespace', config('blueprint.namespace').'\\Http\\Requests'.($controller->namespace() ? '\\'.$controller->namespace() : ''), $stub);
81-
$stub = str_replace('DummyClass', $name, $stub);
82-
$stub = str_replace('// rules...', $this->buildRules($context, $validateStatement), $stub);
80+
$stub = str_replace('{{ namespace }}', config('blueprint.namespace').'\\Http\\Requests'.($controller->namespace() ? '\\'.$controller->namespace() : ''), $stub);
81+
$stub = str_replace('{{ class }}', $name, $stub);
82+
$stub = str_replace('{{ rules }}', $this->buildRules($context, $validateStatement), $stub);
8383

8484
return $stub;
8585
}

src/Generators/Statements/JobGenerator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ protected function getPath(string $name)
5757

5858
protected function populateStub(string $stub, DispatchStatement $dispatchStatement)
5959
{
60-
$stub = str_replace('DummyNamespace', config('blueprint.namespace').'\\Jobs', $stub);
61-
$stub = str_replace('DummyClass', $dispatchStatement->job(), $stub);
62-
$stub = str_replace('// properties...', $this->buildConstructor($dispatchStatement), $stub);
60+
$stub = str_replace('{{ namespace }}', config('blueprint.namespace').'\\Jobs', $stub);
61+
$stub = str_replace('{{ class }}', $dispatchStatement->job(), $stub);
62+
$stub = str_replace('{{ properties }}', $this->buildConstructor($dispatchStatement), $stub);
6363

6464
return $stub;
6565
}

src/Generators/Statements/MailGenerator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ protected function getPath(string $name)
6161

6262
protected function populateStub(string $stub, SendStatement $sendStatement)
6363
{
64-
$stub = str_replace('DummyNamespace', config('blueprint.namespace').'\\Mail', $stub);
65-
$stub = str_replace('DummyClass', $sendStatement->mail(), $stub);
66-
$stub = str_replace('// properties...', $this->buildConstructor($sendStatement), $stub);
64+
$stub = str_replace('{{ namespace }}', config('blueprint.namespace').'\\Mail', $stub);
65+
$stub = str_replace('{{ class }}', $sendStatement->mail(), $stub);
66+
$stub = str_replace('{{ properties }}', $this->buildConstructor($sendStatement), $stub);
6767

6868
return $stub;
6969
}

0 commit comments

Comments
 (0)