Skip to content

Commit a4311c6

Browse files
authored
Publish Blueprint stubs (#312)
1 parent fa288e4 commit a4311c6

31 files changed

+195
-187
lines changed

phpunit.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,4 @@
2424
<directory suffix=".php">./src</directory>
2525
</whitelist>
2626
</filter>
27-
<php>
28-
<const name="STUBS_PATH" value="stubs"/>
29-
</php>
3027
</phpunit>

src/BlueprintServiceProvider.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,17 @@ public function boot()
2323
define('STUBS_PATH', dirname(__DIR__) . '/stubs');
2424
}
2525

26+
if (!defined('CUSTOM_STUBS_PATH')) {
27+
define('CUSTOM_STUBS_PATH', base_path('stubs/blueprint'));
28+
}
29+
2630
$this->publishes([
2731
__DIR__ . '/../config/blueprint.php' => config_path('blueprint.php'),
2832
], 'blueprint-config');
33+
34+
$this->publishes([
35+
dirname(__DIR__) . '/stubs' => CUSTOM_STUBS_PATH,
36+
], 'blueprint-stubs');
2937
}
3038

3139
/**

src/FileMixins.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ public function stub()
1010
{
1111
return function ($path) {
1212
if (!isset($this->stubs[$path])) {
13-
$this->stubs[$path] = $this->get(STUBS_PATH . '/' . $path);
13+
$stubPath = file_exists($customPath = CUSTOM_STUBS_PATH . '/' . $path)
14+
? $customPath
15+
: STUBS_PATH . '/' . $path;
16+
$this->stubs[$path] = $this->get($stubPath);
1417
}
1518

1619
return $this->stubs[$path];

src/Generators/ControllerGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function output(Tree $tree): array
4242

4343
$output = [];
4444

45-
$stub = $this->files->stub('controller/class.stub');
45+
$stub = $this->files->stub('controller.class.stub');
4646

4747
/** @var \Blueprint\Models\Controller $controller */
4848
foreach ($tree->controllers() as $controller) {
@@ -83,7 +83,7 @@ protected function populateStub(string $stub, Controller $controller)
8383

8484
protected function buildMethods(Controller $controller)
8585
{
86-
$template = $this->files->stub('controller/method.stub');
86+
$template = $this->files->stub('controller.method.stub');
8787

8888
$methods = '';
8989

src/Generators/ModelGenerator.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function output(Tree $tree): array
2323
{
2424
$output = [];
2525

26-
$stub = $this->files->stub('model/class.stub');
26+
$stub = $this->files->stub('model.class.stub');
2727

2828
/** @var \Blueprint\Models\Model $model */
2929
foreach ($tree->models() as $model) {
@@ -99,33 +99,33 @@ protected function buildProperties(Model $model)
9999
$properties = '';
100100

101101
if (! $model->usesTimestamps()) {
102-
$properties .= $this->files->stub('model/timestamps.stub');
102+
$properties .= $this->files->stub('model.timestamps.stub');
103103
}
104104

105105
if (config('blueprint.use_guarded')) {
106-
$properties .= $this->files->stub('model/guarded.stub');
106+
$properties .= $this->files->stub('model.guarded.stub');
107107
} else {
108108
$columns = $this->fillableColumns($model->columns());
109109
if (! empty($columns)) {
110-
$properties .= PHP_EOL.str_replace('[]', $this->pretty_print_array($columns, false), $this->files->stub('model/fillable.stub'));
110+
$properties .= PHP_EOL.str_replace('[]', $this->pretty_print_array($columns, false), $this->files->stub('model.fillable.stub'));
111111
} else {
112-
$properties .= $this->files->stub('model/fillable.stub');
112+
$properties .= $this->files->stub('model.fillable.stub');
113113
}
114114
}
115115

116116
$columns = $this->hiddenColumns($model->columns());
117117
if (! empty($columns)) {
118-
$properties .= PHP_EOL.str_replace('[]', $this->pretty_print_array($columns, false), $this->files->stub('model/hidden.stub'));
118+
$properties .= PHP_EOL.str_replace('[]', $this->pretty_print_array($columns, false), $this->files->stub('model.hidden.stub'));
119119
}
120120

121121
$columns = $this->castableColumns($model->columns());
122122
if (! empty($columns)) {
123-
$properties .= PHP_EOL.str_replace('[]', $this->pretty_print_array($columns), $this->files->stub('model/casts.stub'));
123+
$properties .= PHP_EOL.str_replace('[]', $this->pretty_print_array($columns), $this->files->stub('model.casts.stub'));
124124
}
125125

126126
$columns = $this->dateColumns($model->columns());
127127
if (! empty($columns)) {
128-
$properties .= PHP_EOL.str_replace('[]', $this->pretty_print_array($columns, false), $this->files->stub('model/dates.stub'));
128+
$properties .= PHP_EOL.str_replace('[]', $this->pretty_print_array($columns, false), $this->files->stub('model.dates.stub'));
129129
}
130130

131131
return trim($properties);
@@ -134,11 +134,11 @@ protected function buildProperties(Model $model)
134134
protected function buildRelationships(Model $model)
135135
{
136136
$methods = '';
137-
$template = $this->files->stub('model/method.stub');
137+
$template = $this->files->stub('model.method.stub');
138138
$commentTemplate = '';
139139

140140
if (config('blueprint.generate_phpdocs')) {
141-
$commentTemplate = $this->files->stub('model/method-comment.stub');
141+
$commentTemplate = $this->files->stub('model.method.comment.stub');
142142
}
143143

144144
foreach ($model->relationships() as $type => $references) {

src/Generators/StatementGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ protected function buildConstructor($statement)
2626
static $constructor = null;
2727

2828
if (is_null($constructor)) {
29-
$constructor = str_replace('new instance', $this->new_instance, $this->files->stub('partials/constructor.stub'));
29+
$constructor = str_replace('new instance', $this->new_instance, $this->files->stub('constructor.stub'));
3030
}
3131

3232
if (empty($statement->data())) {

src/Generators/Statements/FormRequestGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function output(Tree $tree): array
3333

3434
$output = [];
3535

36-
$stub = $this->files->stub('form-request.stub');
36+
$stub = $this->files->stub('request.stub');
3737

3838
/** @var \Blueprint\Models\Controller $controller */
3939
foreach ($tree->controllers() as $controller) {

src/Generators/TestGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function output(Tree $tree): array
5050

5151
$output = [];
5252

53-
$stub = $this->files->get(STUBS_PATH.'/test/class.stub');
53+
$stub = $this->files->stub('test.class.stub');
5454

5555
/** @var \Blueprint\Models\Controller $controller */
5656
foreach ($tree->controllers() as $controller) {
@@ -524,7 +524,7 @@ private function buildTraits(Controller $controller)
524524
private function testCaseStub()
525525
{
526526
if (empty($this->stubs['test-case'])) {
527-
$this->stubs['test-case'] = $this->files->get(STUBS_PATH.'/test/case.stub');
527+
$this->stubs['test-case'] = $this->files->stub('test.case.stub');
528528
}
529529

530530
return $this->stubs['test-case'];
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)