Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable stub locations #113

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions config/generators.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

return [
/**
* Override stub locations to use a custom stub
*/
'stubs' => [
// 'migration' => 'migration.stub',
// 'pivot' => 'pivot.stub',
// 'schema-change' => 'schema-change.stub',
// 'schema-create' => 'schema-create.stub',
// 'seed' => 'seed.stub',
],
];
13 changes: 12 additions & 1 deletion src/Commands/MigrationMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ protected function getModelPath($name)
*/
protected function compileMigrationStub()
{
$stub = $this->files->get(__DIR__ . '/../stubs/migration.stub');
$stub = $this->files->get($this->getStub());

$this->replaceClassName($stub)
->replaceSchema($stub)
Expand Down Expand Up @@ -245,4 +245,15 @@ protected function getOptions()
['model', null, InputOption::VALUE_OPTIONAL, 'Want a model for this table?', true],
];
}

/**
* Get the stub file for the generator.
*
* @return string
*/
protected function getStub()
{
return config('generators.stubs.migration', __DIR__ . '/../stubs/migration.stub');
}

}
2 changes: 1 addition & 1 deletion src/Commands/PivotMigrationMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected function parseName($name)
*/
protected function getStub()
{
return __DIR__ . '/../stubs/pivot.stub';
return config('generators.stubs.pivot', __DIR__ . '/../stubs/pivot.stub');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/SeedMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected function parseName($name)
*/
protected function getStub()
{
return __DIR__ . '/../stubs/seed.stub';
return config('generators.stubs.seed', __DIR__ . '/../stubs/seed.stub');
}

/**
Expand Down
13 changes: 12 additions & 1 deletion src/GeneratorsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ class GeneratorsServiceProvider extends ServiceProvider
*/
public function boot()
{
//
$this->publishes([
__DIR__ . '/../config/generators.php' => config_path('generators.php'),
], 'config');
}

/**
Expand All @@ -23,6 +25,7 @@ public function boot()
*/
public function register()
{
$this->registerConfig();
$this->registerSeedGenerator();
$this->registerMigrationGenerator();
$this->registerPivotMigrationGenerator();
Expand Down Expand Up @@ -63,4 +66,12 @@ private function registerPivotMigrationGenerator()

$this->commands('command.laracasts.migrate.pivot');
}

/**
* Register the default configuration.
*/
private function registerConfig()
{
$this->mergeConfigFrom(__DIR__ . '/../config/generators.php', 'generators');
}
}
4 changes: 2 additions & 2 deletions src/Migrations/SyntaxBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private function into($wrapper, $placeholder = 'schema_up')
*/
private function getCreateSchemaWrapper()
{
return file_get_contents(__DIR__ . '/../stubs/schema-create.stub');
return file_get_contents(config('generators.stubs.schema-create', __DIR__ . '/../stubs/schema-create.stub'));
}

/**
Expand All @@ -136,7 +136,7 @@ private function getCreateSchemaWrapper()
*/
private function getChangeSchemaWrapper()
{
return file_get_contents(__DIR__ . '/../stubs/schema-change.stub');
return file_get_contents(config('generators.stubs.schema-change', __DIR__ . '/../stubs/schema-change.stub'));
}

/**
Expand Down