|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Console\Commands\Generator; |
|
4
|
|
|
|
|
5
|
|
|
class RepositoryGenerator extends BaseGenerator |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* The name and signature of the console command. |
|
9
|
|
|
* |
|
10
|
|
|
* @var string |
|
11
|
|
|
*/ |
|
12
|
|
|
protected $signature = 'make:repository {name}'; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* The console command description. |
|
16
|
|
|
* |
|
17
|
|
|
* @var string |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $description = 'Create a repository set'; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Execute the console command. |
|
23
|
|
|
* |
|
24
|
|
|
* @return mixed |
|
25
|
|
|
*/ |
|
26
|
|
|
public function handle() |
|
27
|
|
|
{ |
|
28
|
|
|
$targetName = $this->getTargetName(); |
|
29
|
|
|
|
|
30
|
|
|
$this->info("Create repository: $targetName"); |
|
31
|
|
|
$this->generateInterface($targetName); |
|
32
|
|
|
$this->generateRepository($targetName); |
|
33
|
|
|
|
|
34
|
|
|
$this->bindInterface($targetName); |
|
|
|
|
|
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Generate interface file. |
|
39
|
|
|
* |
|
40
|
|
|
* @param $name |
|
41
|
|
|
*/ |
|
42
|
|
|
protected function generateInterface($name) |
|
43
|
|
|
{ |
|
44
|
|
|
$this->proceedAndSaveFile($name, 'repository_interface', |
|
45
|
|
|
$this->getRepositoriesPath().ucwords($name).'RepositoryInterface.php'); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Generate repository file. |
|
50
|
|
|
* |
|
51
|
|
|
* @param $name |
|
52
|
|
|
*/ |
|
53
|
|
|
protected function generateRepository($name) |
|
54
|
|
|
{ |
|
55
|
|
|
$this->proceedAndSaveFile($name, 'repository', |
|
56
|
|
|
$this->getRepositoriesPath().'/Eloquent/'.ucwords($name).'EloquentRepository.php'); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @param string $name |
|
61
|
|
|
* |
|
62
|
|
|
* @return bool |
|
63
|
|
|
*/ |
|
64
|
|
|
protected function bindInterface($name) |
|
65
|
|
|
{ |
|
66
|
|
|
$className = ucwords($name); |
|
67
|
|
|
|
|
68
|
|
|
$bindService = $this->filesystem->get($this->getBindServiceProviderPath()); |
|
69
|
|
|
$key = '//---MORE BINDING---//'; |
|
70
|
|
|
|
|
71
|
|
|
$bind = '$this->app->singleton('.PHP_EOL.' \\App\\Repositories\\'.$className.'RepositoryInterface::class,'.PHP_EOL.' \\App\\Repositories\\Eloquent\\'.$className.'EloquentRepository::class'.PHP_EOL.' );'.PHP_EOL.' '.$key; |
|
72
|
|
|
$bindService = str_replace($key, $bind, $bindService); |
|
73
|
|
|
$this->filesystem->put($this->getBindServiceProviderPath(), $bindService); |
|
74
|
|
|
|
|
75
|
|
|
return true; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|