Skip to content

Commit

Permalink
Composer dump with some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffreyWay committed Feb 26, 2015
1 parent 81a26e0 commit 7d977a2
Showing 1 changed file with 35 additions and 24 deletions.
59 changes: 35 additions & 24 deletions src/Commands/MigrationMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Console\AppNamespaceDetectorTrait;
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Foundation\Composer;
use Laracasts\Generators\Migrations\NameParser;
use Laracasts\Generators\Migrations\SchemaParser;
use Laracasts\Generators\Migrations\SyntaxBuilder;
Expand Down Expand Up @@ -44,22 +45,23 @@ class MigrationMakeCommand extends Command
protected $meta;

/**
* @var MigrationNameParser
* @var Composer
*/
protected $parser;
private $composer;

/**
* Create a new command instance.
*
* @param Filesystem $files
* @param NameParser $parser
* @param Composer $composer
*/
public function __construct(Filesystem $files, NameParser $parser)
public function __construct(Filesystem $files, Composer $composer)
{
parent::__construct();

$this->files = $files;
$this->parser = $parser;
$this->composer = $composer;
}

/**
Expand All @@ -68,6 +70,17 @@ public function __construct(Filesystem $files, NameParser $parser)
* @return mixed
*/
public function fire()
{
$this->meta = (new NameParser)->parse($this->argument('name'));

$this->makeMigration();
$this->makeModel();
}

/**
* Generate the desired migration.
*/
protected function makeMigration()
{
$name = $this->argument('name');

Expand All @@ -76,15 +89,28 @@ public function fire()
return $this->error($this->type.' already exists!');
}

$this->meta = $this->parser->parse($name);

$this->makeDirectory($path);

$this->files->put($path, $this->compileMigrationStub());

$this->info('Migration created successfully.');

$this->makeModel();
$this->composer->dumpAutoloads();
}

/**
* Generate an Eloquent model, if the user wishes.
*/
protected function makeModel()
{
$modelPath = $this->getModelPath($this->getModelName());

if ($this->option('model') && ! $this->files->exists($modelPath)) {
$this->call('make:model', [
'name' => $this->getModelName(),
'--no-migration' => true
]);
}
}

/**
Expand Down Expand Up @@ -135,8 +161,8 @@ protected function compileMigrationStub()
$stub = $this->files->get(__DIR__.'/../stubs/migration.stub');

$this->replaceClassName($stub)
->replaceSchema($stub)
->replaceTableName($stub);
->replaceSchema($stub)
->replaceTableName($stub);

return $stub;
}
Expand Down Expand Up @@ -190,21 +216,6 @@ protected function replaceSchema(&$stub)
return $this;
}

/**
* Generate an Eloquent model, if the user wishes.
*/
protected function makeModel()
{
$modelPath = $this->getModelPath($this->getModelName());

if ($this->option('model') && ! $this->files->exists($modelPath)) {
$this->call('make:model', [
'name' => $this->getModelName(),
'--no-migration' => true
]);
}
}

/**
* Get the class name for the Eloquent model generator.
*
Expand Down

0 comments on commit 7d977a2

Please sign in to comment.