Skip to content

Commit 3cb5180

Browse files
authored
Merge pull request #1 from webfactor/1.2
[EH] integrate backpack crud commands and stubs
2 parents cd2210a + 49921b3 commit 3cb5180

23 files changed

+638
-100
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip
2121
### Security
2222
- Nothing
2323

24+
## 1.2.0 - 2018-03-18
25+
26+
### Added
27+
- integrate backpack crud commands and stubs
28+
2429
## 1.1.1 - 2018-03-17
2530

2631
### Fixed

config/generators.php

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,14 @@
33
return [
44
/*
55
* Services that should be applied by make:entity as default. The classes for 'service'
6-
* have to implement Webfactor\Laravel\Generators\Contracts\MakeServiceInterface and
7-
* conversion uses Webfactor\Laravel\Generators\Contracts\ConversionNameInterface.
6+
* have to implement Webfactor\Laravel\Generators\Contracts\MakeServiceInterface.
87
*/
98
'services' => [
10-
Webfactor\Laravel\Generators\Services\MakeMigrationService::class => [
11-
'name_conversion' => Webfactor\Laravel\Generators\Services\Conversion\MigrationName::class,
12-
'schema' => 'name:string',
13-
],
14-
Webfactor\Laravel\Generators\Services\MakeFactoryService::class => [
15-
'name_conversion' => Webfactor\Laravel\Generators\Services\Conversion\FactoryName::class,
16-
],
17-
Webfactor\Laravel\Generators\Services\MakeSeederService::class => [
18-
'name_conversion' => Webfactor\Laravel\Generators\Services\Conversion\SeederName::class,
19-
],
20-
Webfactor\Laravel\Generators\Services\MakeBackpackCrudService::class => [
21-
'name_conversion' => Webfactor\Laravel\Generators\Services\Conversion\BackpackCrudName::class,
22-
],
9+
Webfactor\Laravel\Generators\Services\MakeBackpackCrudModelService::class,
10+
Webfactor\Laravel\Generators\Services\MakeBackpackCrudControllerService::class,
11+
Webfactor\Laravel\Generators\Services\MakeBackpackCrudRequestService::class,
12+
Webfactor\Laravel\Generators\Services\MakeMigrationService::class,
13+
Webfactor\Laravel\Generators\Services\MakeFactoryService::class,
14+
Webfactor\Laravel\Generators\Services\MakeSeederService::class,
2315
],
2416
];
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?php
2+
3+
namespace Webfactor\Laravel\Generators\Commands;
4+
5+
use Illuminate\Console\GeneratorCommand;
6+
7+
class MakeBackpackCrudController extends GeneratorCommand
8+
{
9+
/**
10+
* The console command name.
11+
*
12+
* @var string
13+
*/
14+
protected $name = 'make:crud-controller';
15+
16+
/**
17+
* The name and signature of the console command.
18+
*
19+
* @var string
20+
*/
21+
protected $signature = 'make:crud-controller {name}';
22+
23+
/**
24+
* The console command description.
25+
*
26+
* @var string
27+
*/
28+
protected $description = 'Generate a Backpack CRUD controller';
29+
30+
/**
31+
* The type of class being generated.
32+
*
33+
* @var string
34+
*/
35+
protected $type = 'Controller';
36+
37+
/**
38+
* Get the destination class path.
39+
*
40+
* @param string $name
41+
*
42+
* @return string
43+
*/
44+
protected function getPath($name)
45+
{
46+
$name = str_replace($this->laravel->getNamespace(), '', $name);
47+
48+
return $this->laravel['path'].'/'.str_replace('\\', '/', $name).'CrudController.php';
49+
}
50+
51+
/**
52+
* Get the stub file for the generator.
53+
*
54+
* @return string
55+
*/
56+
protected function getStub()
57+
{
58+
return __DIR__.'/../../stubs/crud-controller.stub';
59+
}
60+
61+
/**
62+
* Get the default namespace for the class.
63+
*
64+
* @param string $rootNamespace
65+
*
66+
* @return string
67+
*/
68+
protected function getDefaultNamespace($rootNamespace)
69+
{
70+
return $rootNamespace.'\Http\Controllers\Admin';
71+
}
72+
73+
/**
74+
* Replace the table name for the given stub.
75+
*
76+
* @param string $stub
77+
* @param string $name
78+
*
79+
* @return string
80+
*/
81+
protected function replaceNameStrings(&$stub, $name)
82+
{
83+
$table = str_plural(ltrim(strtolower(preg_replace('/[A-Z]/', '_$0', str_replace($this->getNamespace($name).'\\', '', $name))), '_'));
84+
85+
$stub = str_replace('DummyTable', $table, $stub);
86+
$stub = str_replace('dummy_class', strtolower(str_replace($this->getNamespace($name).'\\', '', $name)), $stub);
87+
88+
return $this;
89+
}
90+
91+
/**
92+
* Build the class with the given name.
93+
*
94+
* @param string $name
95+
*
96+
* @return string
97+
*/
98+
protected function buildClass($name)
99+
{
100+
$stub = $this->files->get($this->getStub());
101+
102+
return $this->replaceNamespace($stub, $name)->replaceNameStrings($stub, $name)->replaceClass($stub, $name);
103+
}
104+
105+
/**
106+
* Get the console command options.
107+
*
108+
* @return array
109+
*/
110+
protected function getOptions()
111+
{
112+
return [
113+
114+
];
115+
}
116+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
3+
namespace Webfactor\Laravel\Generators\Commands;
4+
5+
use Illuminate\Support\Str;
6+
use Illuminate\Console\GeneratorCommand;
7+
8+
class MakeBackpackCrudModel extends GeneratorCommand
9+
{
10+
/**
11+
* The console command name.
12+
*
13+
* @var string
14+
*/
15+
protected $name = 'make:crud-model';
16+
17+
/**
18+
* The name and signature of the console command.
19+
*
20+
* @var string
21+
*/
22+
protected $signature = 'make:crud-model {name}';
23+
24+
/**
25+
* The console command description.
26+
*
27+
* @var string
28+
*/
29+
protected $description = 'Generate a Backpack CRUD model';
30+
31+
/**
32+
* The type of class being generated.
33+
*
34+
* @var string
35+
*/
36+
protected $type = 'Model';
37+
38+
/**
39+
* Get the stub file for the generator.
40+
*
41+
* @return string
42+
*/
43+
protected function getStub()
44+
{
45+
return __DIR__.'/../../stubs/crud-model.stub';
46+
}
47+
48+
/**
49+
* Get the default namespace for the class.
50+
*
51+
* @param string $rootNamespace
52+
*
53+
* @return string
54+
*/
55+
protected function getDefaultNamespace($rootNamespace)
56+
{
57+
return $rootNamespace.'\Models';
58+
}
59+
60+
/**
61+
* Replace the table name for the given stub.
62+
*
63+
* @param string $stub
64+
* @param string $name
65+
*
66+
* @return string
67+
*/
68+
protected function replaceTable(&$stub, $name)
69+
{
70+
$name = ltrim(strtolower(preg_replace('/[A-Z]/', '_$0', str_replace($this->getNamespace($name).'\\', '', $name))), '_');
71+
72+
$table = Str::snake(Str::plural($name));
73+
74+
$stub = str_replace('DummyTable', $table, $stub);
75+
76+
return $this;
77+
}
78+
79+
/**
80+
* Build the class with the given name.
81+
*
82+
* @param string $name
83+
*
84+
* @return string
85+
*/
86+
protected function buildClass($name)
87+
{
88+
$stub = $this->files->get($this->getStub());
89+
90+
return $this->replaceNamespace($stub, $name)->replaceTable($stub, $name)->replaceClass($stub, $name);
91+
}
92+
93+
/**
94+
* Get the console command options.
95+
*
96+
* @return array
97+
*/
98+
protected function getOptions()
99+
{
100+
return [
101+
102+
];
103+
}
104+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
namespace Webfactor\Laravel\Generators\Commands;
4+
5+
use Illuminate\Console\GeneratorCommand;
6+
7+
class MakeBackpackCrudRequest extends GeneratorCommand
8+
{
9+
/**
10+
* The console command name.
11+
*
12+
* @var string
13+
*/
14+
protected $name = 'make:crud-request';
15+
16+
/**
17+
* The name and signature of the console command.
18+
*
19+
* @var string
20+
*/
21+
protected $signature = 'make:crud-request {name}';
22+
23+
/**
24+
* The console command description.
25+
*
26+
* @var string
27+
*/
28+
protected $description = 'Generate a Backpack CRUD request';
29+
30+
/**
31+
* The type of class being generated.
32+
*
33+
* @var string
34+
*/
35+
protected $type = 'Request';
36+
37+
/**
38+
* Get the destination class path.
39+
*
40+
* @param string $name
41+
*
42+
* @return string
43+
*/
44+
protected function getPath($name)
45+
{
46+
$name = str_replace($this->laravel->getNamespace(), '', $name);
47+
48+
return $this->laravel['path'].'/'.str_replace('\\', '/', $name).'Request.php';
49+
}
50+
51+
/**
52+
* Get the stub file for the generator.
53+
*
54+
* @return string
55+
*/
56+
protected function getStub()
57+
{
58+
return __DIR__.'/../../stubs/crud-request.stub';
59+
}
60+
61+
/**
62+
* Get the default namespace for the class.
63+
*
64+
* @param string $rootNamespace
65+
*
66+
* @return string
67+
*/
68+
protected function getDefaultNamespace($rootNamespace)
69+
{
70+
return $rootNamespace.'\Http\Requests\Admin';
71+
}
72+
73+
/**
74+
* Get the console command options.
75+
*
76+
* @return array
77+
*/
78+
protected function getOptions()
79+
{
80+
return [
81+
82+
];
83+
}
84+
}

src/Contracts/ConversionNameInterface.php

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/Contracts/MakeServiceAbstract.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@
77
abstract class MakeServiceAbstract
88
{
99
protected $command;
10-
protected $options;
1110
protected $entity;
1211

13-
public function __construct(MakeEntity $command, array $options)
12+
public function __construct(MakeEntity $command)
1413
{
1514
$this->command = $command;
16-
$this->options = $options;
1715
$this->entity = $command->argument('entity');
1816
}
1917
}

src/GeneratorsServiceProvider.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
namespace Webfactor\Laravel\Generators;
44

55
use Illuminate\Support\ServiceProvider;
6+
use Webfactor\Laravel\Generators\Commands\MakeBackpackCrudController;
7+
use Webfactor\Laravel\Generators\Commands\MakeBackpackCrudModel;
8+
use Webfactor\Laravel\Generators\Commands\MakeBackpackCrudRequest;
69
use Webfactor\Laravel\Generators\Commands\MakeEntity;
710

811
class GeneratorsServiceProvider extends ServiceProvider
@@ -17,6 +20,9 @@ public function boot()
1720
if ($this->app->runningInConsole()) {
1821
$this->commands([
1922
MakeEntity::class,
23+
MakeBackpackCrudController::class,
24+
MakeBackpackCrudModel::class,
25+
MakeBackpackCrudRequest::class,
2026
]);
2127

2228
$this->publishes([

0 commit comments

Comments
 (0)