Skip to content

Commit 167ac89

Browse files
committed
updated code generation
1 parent 858c32e commit 167ac89

File tree

4 files changed

+35
-18
lines changed

4 files changed

+35
-18
lines changed

src/Commands/RepositoryMakeCommand.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,12 @@ protected function buildClass($name)
5252

5353
$scopes = $this->option('scopes');
5454

55-
return (new Replacer(parent::buildClass($name)))
56-
->replace($model, $scopes);
55+
$stub = (new Replacer(parent::buildClass($name)))
56+
->replace($scopes);
57+
58+
$stub = str_replace('NamespacedDummyModel', $model, $stub);
59+
60+
return str_replace('DummyModel', last(explode('\\', $model)), $stub);
5761
}
5862

5963
/**

src/Commands/RepositoryMakeMainCommand.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,16 @@ public function handle()
4141

4242
$this->createRepository();
4343

44-
$this->createScopes();
44+
$scope = $this->option('scope');
4545

46-
if ($scope = $this->option('scope')) {
46+
$this->createScopes(
47+
$scope
48+
? Str::singular($scope) . Str::plural($this->getNameInput()) . 'Scope'
49+
: $scope,
50+
Str::camel($scope)
51+
);
52+
53+
if ($scope) {
4754
$this->createScope($scope);
4855
}
4956
}
@@ -63,26 +70,28 @@ protected function createRepository()
6370
}
6471

6572
/**
66-
* Create a repository.
73+
* Create a repository scopes.
6774
*
6875
* @return void
6976
*/
70-
protected function createScopes()
77+
protected function createScopes($scope, $scopeName)
7178
{
7279
$this->call('make:repository:scopes', [
7380
'name' => $this->getNamespacedScopes(),
81+
'--scope' => $scope,
82+
'--scope_name' => $scopeName,
7483
]);
7584
}
7685

7786
/**
78-
* Create a repository.
87+
* Create a repository scope.
7988
*
8089
* @return void
8190
*/
8291
protected function createScope($scope)
8392
{
8493
$this->call('make:repository:scope', [
85-
'name' => $this->getNamespacedScope($scope),
94+
'name' => $this->getNamespacedScope($scope)
8695
]);
8796
}
8897

@@ -108,8 +117,9 @@ protected function rootNamespace()
108117

109118
private function getNamespacedModel()
110119
{
111-
return $this->baseNamespace .'\Models\\'
112-
. Str::singular($this->getNameInput());
120+
return implode(
121+
'\\', explode('/', trim($this->argument('modelName')))
122+
);
113123
}
114124

115125
private function getNamespacedScopes()

src/Commands/RepositoryScopesMakeCommand.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class RepositoryScopesMakeCommand extends GeneratorCommand
1212
*
1313
* @var string
1414
*/
15-
protected $signature = 'make:repository:scopes {name}';
15+
protected $signature = 'make:repository:scopes {name} {--scope=} {--scope_name=}';
1616

1717
/**
1818
* The console command description.
@@ -48,8 +48,16 @@ public function handle()
4848
*/
4949
protected function buildClass($name)
5050
{
51-
return (new Replacer(parent::buildClass($name)))
51+
$stub = (new Replacer(parent::buildClass($name)))
5252
->replace($name);
53+
54+
if ($scope = $this->option('scope')) {
55+
$stub = str_replace('SearchScope', $scope, $stub);
56+
$scopeName = $this->option('scope_name');
57+
$stub = str_replace('search', $scopeName, $stub);
58+
}
59+
60+
return $stub;
5361
}
5462

5563
/**

src/Commands/stubs/repository.stub

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace DummyNamespace;
44

5-
use App\DummyModel;
5+
use App\NamespacedDummyModel;
66
use AwesIO\Repository\Eloquent\BaseRepository;
77
use NamespacedDummyScope;
88

@@ -15,11 +15,6 @@ class DummyClass extends BaseRepository
1515
*/
1616
protected $searchable = [];
1717

18-
/**
19-
* Returns DocDummyModel model's full class name.
20-
*
21-
* @return string
22-
*/
2318
public function entity()
2419
{
2520
return DummyModel::class;

0 commit comments

Comments
 (0)