Skip to content

Commit 470ee04

Browse files
committed
add support for automatic package discovery (Laravel 5.5)
1 parent 2530cd7 commit 470ee04

12 files changed

+66
-36
lines changed

composer.json

+9-2
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,19 @@
1717
}
1818
],
1919
"require": {
20-
"php": ">=5.6.4"
20+
"php": ">=7.0.0"
2121
},
2222
"autoload": {
2323
"psr-4": {
2424
"Bpocallaghan\\Generators\\": "src/"
2525
}
2626
},
27-
"minimum-stability": "dev"
27+
"minimum-stability": "dev",
28+
"extra": {
29+
"laravel": {
30+
"providers": [
31+
"Bpocallaghan\\Generators\\GeneratorsServiceProvider"
32+
]
33+
}
34+
}
2835
}

readme.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ You can publish the stubs. You can add your own stubs to generate.
55

66
Interested in a laravel admin starter project where the package is being used. [Admin Starter Project](https://github.com/bpocallaghan/laravel-admin-starter)
77

8-
Laravel 5.1, use tag 2.1.3, Laravel 5.2 or Laravel 5.3, use branch 3, Laravel 5.4 use latest
8+
```
9+
Laravel 5.1 - v2.1.3
10+
Laravel 5.2 - v3.0.3
11+
Laravel 5.3 - v3.0.3
12+
Laravel 5.4 - v4.1.9
13+
Laravel 5.5 - v5.0.0+
14+
```
915

1016
## Commands
1117
```bash
@@ -70,7 +76,7 @@ Update your project's `composer.json` file.
7076
composer require bpocallaghan/generators --dev
7177
```
7278

73-
App the Service Provider
79+
Add the Service Provider (Laravel 5.5 has automatic discovery of packages)
7480
You'll only want to use these generators for local development, add the provider in `app/Providers/AppServiceProvider.php`:
7581

7682
```php

src/Commands/EventGenerateCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class EventGenerateCommand extends GeneratorCommand
3434
*
3535
* @return void
3636
*/
37-
public function fire()
37+
public function handle()
3838
{
3939
$provider = $this->laravel->getProvider(EventServiceProvider::class);
4040

src/Commands/FileCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ private function getFileName()
6767
*
6868
* @return void
6969
*/
70-
public function fire()
70+
public function handle()
7171
{
7272
// setup
7373
$this->setSettings();

src/Commands/GeneratorCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function __construct(Filesystem $files, Composer $composer)
5050
*
5151
* @return void
5252
*/
53-
public function fire()
53+
public function handle()
5454
{
5555
$args = [
5656
'name' => $this->argumentName(),

src/Commands/ListenerCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ListenerCommand extends GeneratorCommand
3636
*
3737
* @return void
3838
*/
39-
public function fire()
39+
public function handle()
4040
{
4141
if (!$this->option('event')) {
4242
return $this->error('Missing required option: --event=*NameOfEvent*');

src/Commands/MigrationCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class MigrationCommand extends GeneratorCommand
4242
*
4343
* @return mixed
4444
*/
45-
public function fire()
45+
public function handle()
4646
{
4747
$this->meta = (new NameParser)->parse($this->argumentName());
4848

src/Commands/MigrationPivotCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class MigrationPivotCommand extends GeneratorCommand
3232
*
3333
* @return mixed
3434
*/
35-
public function fire()
35+
public function handle()
3636
{
3737
$name = $this->parseName($this->getNameInput());
3838
$path = $this->getPath($name);

src/Commands/ModelCommand.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ class ModelCommand extends GeneratorCommand
3232
*
3333
* @return void
3434
*/
35-
public function fire()
35+
public function handle()
3636
{
37-
parent::fire();
37+
parent::handle();
3838

3939
if ($this->option('migration')) {
4040
$name = $this->getMigrationName();

src/Commands/PublishCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class PublishCommand extends GeneratorCommand
2525
/**
2626
* Execute the command
2727
*/
28-
public function fire()
28+
public function handle()
2929
{
3030
$this->copyConfigFile();
3131
$this->copyStubsDirectory();

src/Commands/ResourceCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class ResourceCommand extends GeneratorCommand
3535
*
3636
* @return void
3737
*/
38-
public function fire()
38+
public function handle()
3939
{
4040
$this->resource = $this->getResourceOnly();
4141
$this->settings = config('generators.defaults');

src/GeneratorsServiceProvider.php

+39-22
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,31 @@
22

33
namespace Bpocallaghan\Generators;
44

5+
use Bpocallaghan\Generators\Commands\JobCommand;
6+
use Bpocallaghan\Generators\Commands\FileCommand;
7+
use Bpocallaghan\Generators\Commands\SeedCommand;
8+
use Bpocallaghan\Generators\Commands\ViewCommand;
9+
use Bpocallaghan\Generators\Commands\EventCommand;
10+
use Bpocallaghan\Generators\Commands\ModelCommand;
11+
use Bpocallaghan\Generators\Commands\TraitCommand;
12+
use Bpocallaghan\Generators\Commands\ConsoleCommand;
13+
use Bpocallaghan\Generators\Commands\PublishCommand;
14+
use Bpocallaghan\Generators\Commands\ContractCommand;
15+
use Bpocallaghan\Generators\Commands\ListenerCommand;
16+
use Bpocallaghan\Generators\Commands\ResourceCommand;
17+
use Bpocallaghan\Generators\Commands\MigrationCommand;
18+
use Bpocallaghan\Generators\Commands\ControllerCommand;
19+
use Bpocallaghan\Generators\Commands\RepositoryCommand;
20+
use Bpocallaghan\Generators\Commands\MiddlewareCommand;
21+
use Bpocallaghan\Generators\Commands\NotificationCommand;
22+
use Bpocallaghan\Generators\Commands\MigrationPivotCommand;
23+
use Bpocallaghan\Generators\Commands\EventGenerateCommand;
524
use Illuminate\Support\ServiceProvider;
625

726
class GeneratorsServiceProvider extends ServiceProvider
827
{
928
private $commandPath = 'command.bpocallaghan.';
1029

11-
private $packagePath = 'Bpocallaghan\Generators\Commands\\';
12-
1330
/**
1431
* Bootstrap the application events.
1532
*
@@ -32,33 +49,33 @@ public function register()
3249
$this->mergeConfigFrom($configPath, 'generators');
3350

3451
// register all the artisan commands
35-
$this->registerCommand('PublishCommand', 'publish');
52+
$this->registerCommand(PublishCommand::class, 'publish');
3653

37-
$this->registerCommand('ModelCommand', 'model');
38-
$this->registerCommand('ViewCommand', 'view');
39-
$this->registerCommand('ControllerCommand', 'controller');
54+
$this->registerCommand(ModelCommand::class, 'model');
55+
$this->registerCommand(ViewCommand::class, 'view');
56+
$this->registerCommand(ControllerCommand::class, 'controller');
4057

41-
$this->registerCommand('MigrationCommand', 'migration');
42-
$this->registerCommand('MigrationPivotCommand', 'migrate.pivot');
43-
$this->registerCommand('SeedCommand', 'seed');
58+
$this->registerCommand(MigrationCommand::class, 'migration');
59+
$this->registerCommand(MigrationPivotCommand::class, 'migrate.pivot');
60+
$this->registerCommand(SeedCommand::class, 'seed');
4461

45-
$this->registerCommand('NotificationCommand', 'notification');
62+
$this->registerCommand(NotificationCommand::class, 'notification');
4663

47-
$this->registerCommand('EventCommand', 'event');
48-
$this->registerCommand('ListenerCommand', 'listener');
49-
$this->registerCommand('EventGenerateCommand', 'event.generate');
64+
$this->registerCommand(EventCommand::class, 'event');
65+
$this->registerCommand(ListenerCommand::class, 'listener');
66+
$this->registerCommand(EventGenerateCommand::class, 'event.generate');
5067

51-
$this->registerCommand('TraitCommand', 'trait');
52-
$this->registerCommand('RepositoryCommand', 'repository');
53-
$this->registerCommand('ContractCommand', 'contract');
68+
$this->registerCommand(TraitCommand::class, 'trait');
69+
$this->registerCommand(RepositoryCommand::class, 'repository');
70+
$this->registerCommand(ContractCommand::class, 'contract');
5471

55-
$this->registerCommand('JobCommand', 'job');
56-
$this->registerCommand('ConsoleCommand', 'console');
72+
$this->registerCommand(JobCommand::class, 'job');
73+
$this->registerCommand(ConsoleCommand::class, 'console');
5774

58-
$this->registerCommand('MiddlewareCommand', 'middleware');
75+
$this->registerCommand(MiddlewareCommand::class, 'middleware');
5976

60-
$this->registerCommand('ResourceCommand', 'resource');
61-
$this->registerCommand('FileCommand', 'file');
77+
$this->registerCommand(ResourceCommand::class, 'resource');
78+
$this->registerCommand(FileCommand::class, 'file');
6279
}
6380

6481
/**
@@ -70,7 +87,7 @@ public function register()
7087
private function registerCommand($class, $command)
7188
{
7289
$this->app->singleton($this->commandPath . $command, function ($app) use ($class) {
73-
return $app[$this->packagePath . $class];
90+
return $app[$class];
7491
});
7592

7693
$this->commands($this->commandPath . $command);

0 commit comments

Comments
 (0)