Skip to content

Commit 189af89

Browse files
committed
add publish command
1 parent 5ed8aa2 commit 189af89

File tree

5 files changed

+56
-67
lines changed

5 files changed

+56
-67
lines changed

src/Classes/ControllerGenerator.php

Lines changed: 4 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Http\Controllers\Controller;
66
use Illuminate\Http\Request;
7+
use Illuminate\Support\Str;
78
use Nette\PhpGenerator\ClassType;
89
use Nette\PhpGenerator\PhpNamespace;
910
use Shetabit\ModuleGenerator\Helpers\Helper;
@@ -27,10 +28,7 @@ class ControllerGenerator
2728
*/
2829
protected $baseRelationName;
2930
protected $attributes;
30-
<<<<<<< HEAD
31-
=======
3231
protected $config;
33-
>>>>>>> 73a07f9... first commit
3432

3533
public function __construct($module, $models)
3634
{
@@ -80,18 +78,6 @@ public function generateControllerTemplates($option): PhpNamespace
8078

8179
public function setMethodToController($class, $option, $namespace)
8280
{
83-
<<<<<<< HEAD
84-
if (strpos($option , 'R') == true) {
85-
$this->indexAndShowMethodGenerator($class);
86-
}
87-
if (strpos($option, 'C') == true) {
88-
$this->createAndStoreMethodGenerator($class);
89-
}
90-
if (strpos($option, 'U') == true) {
91-
$this->editAndUpdateMethodGenerator($class, $namespace);
92-
}
93-
if (strpos($option, 'D') == true) {
94-
=======
9581
if (str_contains($option , 'R')) {
9682
$this->indexAndShowMethodGenerator($class);
9783
}
@@ -102,7 +88,6 @@ public function setMethodToController($class, $option, $namespace)
10288
$this->editAndUpdateMethodGenerator($class , $namespace);
10389
}
10490
if (str_contains($option, 'D')) {
105-
>>>>>>> 73a07f9... first commit
10691
$this->destroyMethodGenerator($class);
10792
}
10893
}
@@ -112,16 +97,6 @@ public function indexAndShowMethodGenerator(classType $class)
11297
$method = $class->addMethod('index');
11398
if (key_exists('Relations', $this->attributes)) {
11499
$method->addBody('$' . strtolower($this->modelName) . 's = ' . ucfirst($this->modelName) . '::withCommonRelations()->get();' . PHP_EOL)
115-
<<<<<<< HEAD
116-
->addBody('return response()->json($' . strtolower($this->modelName) . 's);');
117-
} else {
118-
$method->addBody('$' . strtolower($this->modelName) . 's = ' . ucfirst($this->modelName) . '::query()->get();' . PHP_EOL)
119-
->addBody('return response()->json($' . strtolower($this->modelName) . 's);');
120-
}
121-
$class->addMethod('show')
122-
->addBody('$' . strtolower($this->modelName) . ' = ' . ucfirst($this->modelName) . '::query()->findOrFail($id);' . PHP_EOL)
123-
->addBody('return response()->json($' . strtolower($this->modelName) . ');')
124-
=======
125100
->addBody($this->config['return']);
126101
} else {
127102
$method->addBody('$' . strtolower($this->modelName) . 's = ' . ucfirst($this->modelName) . '::query()->get();' . PHP_EOL)
@@ -130,7 +105,6 @@ public function indexAndShowMethodGenerator(classType $class)
130105
$class->addMethod('show')
131106
->addBody('$' . strtolower($this->modelName) . ' = ' . ucfirst($this->modelName) . '::query()->findOrFail($id);' . PHP_EOL)
132107
->addBody($this->config['return'])
133-
>>>>>>> 73a07f9... first commit
134108
->addParameter('id')->setType('Int');
135109
}
136110

@@ -159,12 +133,9 @@ public function associateInStore($method)
159133
{
160134
if (key_exists('Relations', $this->attributes)) {
161135
foreach ($this->attributes['Relations'] as $typeRelation => $relations) {
162-
<<<<<<< HEAD
163-
=======
164136
if (!is_array($relations) && Str::camel($relations) == 'morphTo'){
165137
return '';
166138
}
167-
>>>>>>> 73a07f9... first commit
168139
foreach ($relations as $value) {
169140
$this->baseRelationName = explode('::', $value)[1];
170141
$this->relationName = Helper::configurationRelationsName($this->baseRelationName, $typeRelation);
@@ -174,36 +145,23 @@ public function associateInStore($method)
174145
}
175146
}
176147

177-
<<<<<<< HEAD
178-
public function editAndUpdateMethodGenerator(ClassType $class, $namespace)
179-
=======
148+
180149
public function editAndUpdateMethodGenerator(ClassType $class , $namespace)
181-
>>>>>>> 73a07f9... first commit
182150
{
183151
$method = $class->addMethod('edit');
184152
if (key_exists('Relations', $this->attributes)) {
185153
$method->addBody('$' . strtolower($this->modelName) . ' = ' . ucfirst($this->modelName) . '::withCommonRelations()->findOrFail($id);' . PHP_EOL)
186-
<<<<<<< HEAD
187-
->addBody('return response()->json($' . strtolower($this->modelName) . ');');
188-
} else {
189-
$method->addBody('$' . strtolower($this->modelName) . ' = ' . ucfirst($this->modelName) . '::query()->findOrFail($id);' . PHP_EOL)
190-
->addBody('return response()->json($' . strtolower($this->modelName) . ');');
191-
=======
192154
->addBody($this->config['return']);
193155
} else {
194156
$method->addBody('$' . strtolower($this->modelName) . ' = ' . ucfirst($this->modelName) . '::query()->findOrFail($id);' . PHP_EOL)
195157
->addBody($this->config['return']);
196-
>>>>>>> 73a07f9... first commit
197158
};
198159
$method->addParameter('id')->setType('Int');
199160

200161
$method = $class->addMethod('update')
201162
->addBody('$' . strtolower($this->modelName) . ' = ' . ucfirst($this->modelName) . '::query()->findOrFail($id);');
202-
<<<<<<< HEAD
203-
$this->UpdateMethodFindIntoRelation($method, $namespace);
204-
=======
163+
205164
$this->UpdateMethodFindIntoRelation($method , $namespace);
206-
>>>>>>> 73a07f9... first commit
207165
$this->associateInUpdate($method);
208166
$method->addBody('$' . strtolower($this->modelName) . '->fill($request->all());')
209167
->addBody('$' . strtolower($this->modelName) . '->save();'.PHP_EOL)
@@ -215,20 +173,14 @@ public function editAndUpdateMethodGenerator(ClassType $class , $namespace)
215173
$method->addParameter('id')->setType('Int');
216174
}
217175

218-
<<<<<<< HEAD
219-
public function UpdateMethodFindIntoRelation($method, $namespace)
220-
{
221-
if (key_exists('Relations', $this->attributes)) {
222-
foreach ($this->attributes['Relations'] as $typeRelation => $relations) {
223-
=======
176+
224177
public function UpdateMethodFindIntoRelation($method ,$namespace)
225178
{
226179
if (key_exists('Relations', $this->attributes)) {
227180
foreach ($this->attributes['Relations'] as $typeRelation => $relations) {
228181
if (!is_array($relations) && Str::camel($relations) == 'morphTo'){
229182
return '';
230183
}
231-
>>>>>>> 73a07f9... first commit
232184
foreach ($relations as $value) {
233185
$this->baseRelationName = explode('::', $value)[1];
234186
$method->addBody('$' . strtolower($this->baseRelationName) . ' = ' . ucfirst($this->baseRelationName) . '::query()->findOrFail($request->' . strtolower($this->baseRelationName) . '_id);');
@@ -242,12 +194,9 @@ public function associateInUpdate($method)
242194
{
243195
if (key_exists('Relations', $this->attributes)) {
244196
foreach ($this->attributes['Relations'] as $typeRelation => $relations) {
245-
<<<<<<< HEAD
246-
=======
247197
if (!is_array($relations) && Str::camel($relations) == 'morphTo'){
248198
return '';
249199
}
250-
>>>>>>> 73a07f9... first commit
251200
foreach ($relations as $value) {
252201
$this->baseRelationName = explode('::', $value)[1];
253202
$this->relationName = Helper::configurationRelationsName($this->baseRelationName, $typeRelation);
@@ -261,11 +210,7 @@ public function destroyMethodGenerator(ClassType $class)
261210
{
262211
$class->addMethod('destroy')
263212
->addBody('$' . strtolower($this->modelName) . ' = ' . ucfirst($this->modelName) . '::destroy($id);' . PHP_EOL)
264-
<<<<<<< HEAD
265-
->addBody('return response()->json($' . strtolower($this->modelName) . ');')
266-
=======
267213
->addBody($this->config['return'])
268-
>>>>>>> 73a07f9... first commit
269214
->addParameter('id')->setType('Int');
270215
}
271216

src/Classes/ModelGenerator.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ class ModelGenerator
1717
protected $module;
1818
protected $pathOfModel;
1919
protected array $withRelation = [];
20-
<<<<<<< HEAD
21-
=======
2220
protected $modelName;
23-
>>>>>>> 73a07f9... first commit
21+
2422

2523
public function __construct($module , $models)
2624
{
@@ -131,8 +129,6 @@ public function addWithCommonRelations(ClassType $class)
131129
->addBody('}')
132130
->addParameter('query');
133131
}
134-
<<<<<<< HEAD
135-
=======
136132

137133
public function morphRelation($class)
138134
{
@@ -142,5 +138,4 @@ public function morphRelation($class)
142138
->addBody('return $this->morphTo();')
143139
->setReturnType('Illuminate\Database\Eloquent\Relations\morphTo');
144140
}
145-
>>>>>>> 73a07f9... first commit
146141
}

src/Commands/GenerateModuleCommand.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ public function handle()
4747
die();
4848
}
4949

50-
$this->callSilent('vendor:publish', ['--tag' => 'config' ,'--force' => true]);
51-
5250
$processes = count(\config()->get('modulegenerator') , COUNT_RECURSIVE);
5351
$Progress = $this->getOutput()->createProgressBar($processes);
5452
$Progress->setBarCharacter("/");
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace Shetabit\ModuleGenerator\Commands;
4+
5+
6+
use Illuminate\Console\Command;
7+
use Shetabit\ModuleGenerator\Contracts\ModuleGenerator;
8+
use Symfony\Component\Console\Input\InputArgument;
9+
10+
class PublishModuleGeneratorCommand extends Command
11+
{
12+
/**
13+
* The name and signature of the console command.
14+
*
15+
* @var string
16+
*/
17+
protected $signature = 'generator:publish';
18+
19+
/**
20+
* The console command description.
21+
*
22+
* @var string
23+
*/
24+
protected $description = 'create your module';
25+
26+
/**
27+
* Create a new command instance.
28+
*
29+
* @return void
30+
*/
31+
public function __construct()
32+
{
33+
parent::__construct();
34+
35+
}
36+
37+
/**
38+
* Execute the console command.
39+
*
40+
* @return mixed
41+
*/
42+
public function handle()
43+
{
44+
$this->info("publishing ...");
45+
$this->callSilent('vendor:publish', ['--tag' => 'config' ,'--force' => true]);
46+
$this->info("publish successfully");
47+
48+
}
49+
}

src/Provider/GeneratorServiceProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Support\ServiceProvider;
66
use Shetabit\ModuleGenerator\Commands\GenerateModuleCommand;
7+
use Shetabit\ModuleGenerator\Commands\PublishModuleGeneratorCommand;
78
use Shetabit\ModuleGenerator\Contracts\ControllerGenerator;
89
use Shetabit\ModuleGenerator\Contracts\ForeignKeyGenerator;
910
use Shetabit\ModuleGenerator\Contracts\MigrationGenerator;
@@ -44,6 +45,7 @@ public function boot()
4445
if ($this->app->runningInConsole()) {
4546
$this->commands([
4647
GenerateModuleCommand::class,
48+
PublishModuleGeneratorCommand::class
4749
]);
4850
}
4951

0 commit comments

Comments
 (0)