diff --git a/src/BlueprintCommand.php b/src/BlueprintCommand.php index f36e01d3..9e354b57 100644 --- a/src/BlueprintCommand.php +++ b/src/BlueprintCommand.php @@ -50,27 +50,8 @@ public function handle() } $contents = $this->files->get($file); - - $blueprint = new Blueprint(); - - $blueprint->registerLexer(new \Blueprint\Lexers\ModelLexer()); - $blueprint->registerLexer(new \Blueprint\Lexers\ControllerLexer(new \Blueprint\Lexers\StatementLexer())); - - $blueprint->registerGenerator(new \Blueprint\Generators\MigrationGenerator($this->files)); - $blueprint->registerGenerator(new \Blueprint\Generators\ModelGenerator($this->files)); - $blueprint->registerGenerator(new \Blueprint\Generators\FactoryGenerator($this->files)); - - $blueprint->registerGenerator(new \Blueprint\Generators\ControllerGenerator($this->files)); - $blueprint->registerGenerator(new \Blueprint\Generators\Statements\EventGenerator($this->files)); - $blueprint->registerGenerator(new \Blueprint\Generators\Statements\FormRequestGenerator($this->files)); - $blueprint->registerGenerator(new \Blueprint\Generators\Statements\JobGenerator($this->files)); - $blueprint->registerGenerator(new \Blueprint\Generators\Statements\MailGenerator($this->files)); - $blueprint->registerGenerator(new \Blueprint\Generators\Statements\ViewGenerator($this->files)); - $blueprint->registerGenerator(new \Blueprint\Generators\RouteGenerator($this->files)); - - $tokens = $blueprint->parse($contents); - $registry = $blueprint->analyze($tokens); - $generated = $blueprint->generate($registry); + $blueprint = resolve(Blueprint::class); + $generated = Builder::execute($blueprint, $contents); collect($generated)->each(function ($files, $action) { $this->line(Str::studly($action) . ':', $this->outputStyle($action)); diff --git a/src/BlueprintServiceProvider.php b/src/BlueprintServiceProvider.php index 35306d92..4b3f69f8 100644 --- a/src/BlueprintServiceProvider.php +++ b/src/BlueprintServiceProvider.php @@ -31,12 +31,33 @@ function ($app) { return new BlueprintCommand($app['files']); } ); + $this->app->bind('command.blueprint.erase', function ($app) { return new EraseCommand($app['files']); } ); + $this->app->singleton(Blueprint::class, function ($app) { + $blueprint = new Blueprint(); + $blueprint->registerLexer(new \Blueprint\Lexers\ModelLexer()); + $blueprint->registerLexer(new \Blueprint\Lexers\ControllerLexer(new \Blueprint\Lexers\StatementLexer())); + + $blueprint->registerGenerator(new \Blueprint\Generators\MigrationGenerator($app['files'])); + $blueprint->registerGenerator(new \Blueprint\Generators\ModelGenerator($app['files'])); + $blueprint->registerGenerator(new \Blueprint\Generators\FactoryGenerator($app['files'])); + + $blueprint->registerGenerator(new \Blueprint\Generators\ControllerGenerator($app['files'])); + $blueprint->registerGenerator(new \Blueprint\Generators\Statements\EventGenerator($app['files'])); + $blueprint->registerGenerator(new \Blueprint\Generators\Statements\FormRequestGenerator($app['files'])); + $blueprint->registerGenerator(new \Blueprint\Generators\Statements\JobGenerator($app['files'])); + $blueprint->registerGenerator(new \Blueprint\Generators\Statements\MailGenerator($app['files'])); + $blueprint->registerGenerator(new \Blueprint\Generators\Statements\ViewGenerator($app['files'])); + $blueprint->registerGenerator(new \Blueprint\Generators\RouteGenerator($app['files'])); + + return $blueprint; + }); + $this->commands([ 'command.blueprint.build', 'command.blueprint.erase', @@ -53,6 +74,7 @@ public function provides() return [ 'command.blueprint.build', 'command.blueprint.erase', + Blueprint::class, ]; } } diff --git a/src/Builder.php b/src/Builder.php new file mode 100644 index 00000000..a2fd5c6b --- /dev/null +++ b/src/Builder.php @@ -0,0 +1,19 @@ +parse($draft); + $registry = $blueprint->analyze($tokens); + $generated = $blueprint->generate($registry); + + // TODO: save to .blueprint + + return $generated; + } +} \ No newline at end of file diff --git a/tests/Unit/BuilderTest.php b/tests/Unit/BuilderTest.php new file mode 100644 index 00000000..71c6c8d7 --- /dev/null +++ b/tests/Unit/BuilderTest.php @@ -0,0 +1,39 @@ +expects('parse') + ->with($draft) + ->andReturn($tokens); + $blueprint->expects('analyze') + ->with($tokens) + ->andReturn($registry); + $blueprint->expects('generate') + ->with($registry) + ->andReturn($generated); + + $actual = Builder::execute($blueprint, $draft); + + $this->assertSame($generated, $actual); + } +}