-
Notifications
You must be signed in to change notification settings - Fork 5
/
ioc.sh
executable file
·175 lines (137 loc) · 4.35 KB
/
ioc.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/bin/bash
# Variables.
contract="Contract.php"
eloquent="Eloquent"
repository="Repository.php"
provider="ServiceProvider"
controller="Controller"
FILE="./config/app.php"
#Reading the user input
read -p "$(tput setaf 3)Please enter the desired Module name : $(tput sgr0)" repoName
#Creates the desired Model, Service Provider and Controller.
function createRepoAndContract {
# create Model
php artisan make:model ${repoName^} -m
# create Service Provider
php artisan make:provider ${repoName^}${provider}
# create Controller
php artisan make:controller ${repoName^}${controller}
}
createRepoAndContract
#Creates the module related Repositories directory and
# files inside the App directory
function createRepositoryDirectory {
mkdir ./app/Repositories 2> /dev/null
echo "*$(tput setaf 6)Repositories directory created successfully inside the App directory.$(tput sgr0)"
mkdir ./app/Repositories/${repoName^} && touch ./app/Repositories/${repoName^}/${repoName^}${contract} && touch ./app/Repositories/${repoName^}/${eloquent}${repoName^}${repository}
echo "*$(tput setaf 6)Repository and Contract files created successfully.$(tput sgr0)"
}
createRepositoryDirectory
function registerServiceProvider {
# register service provider inside config/app.php
string='App\\Providers\\'${repoName^}${provider}'::class,'
if [ ! -z $(grep -e "\t""$string" "$FILE") ];
then
echo "*$(tput setaf 6)Service Provider is already registered!$(tput sgr0)"
else
sed -i -e '/App\\Providers\\RouteServiceProvider::class,/a \ \t\t'${string} ${FILE} 2> /dev/null
echo "*$(tput setaf 6)Service Provider registered successfully inside app.php of the config directory.$(tput sgr0)"
fi
}
registerServiceProvider
function writeContractBoilerPlate {
echo "<?php
namespace App\Repositories\\${repoName^};
interface ${repoName^}Contract {
//
}" > ./app/Repositories/${repoName^}/${repoName^}${contract}
}
writeContractBoilerPlate
function writeRepositoryBoilerPlate {
echo "<?php
namespace App\Repositories\\${repoName^};
use App\Repositories\\${repoName^}\\${repoName^}Contract;
class ${eloquent}${repoName^}Repository implements ${repoName^}Contract {
//
}" > ./app/Repositories/${repoName^}/${eloquent}${repoName^}${repository}
}
writeRepositoryBoilerPlate
function bindContractToRepository {
echo "<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class ${repoName^}${provider} extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
//
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
\$this->app->bind('App\Repositories\\${repoName^}\\${repoName^}Contract',
'App\Repositories\\${repoName^}\\${eloquent}${repoName^}Repository');
}
}" > ./app/Providers/${repoName^}${provider}.php
if [[ $? -eq 0 ]]; then
echo "*$(tput setaf 6)Contract and Repository binding in the Service Provider was successful.$(tput sgr0)"
fi
}
bindContractToRepository
# Creates view folder
function createViews {
mkdir ./resources/views/${repoName,,} && touch ./resources/views/${repoName,,}/create.blade.php && touch ./resources/views/${repoName,,}/edit.blade.php && touch ./resources/views/${repoName,,}/index.blade.php
echo "*$(tput setaf 6)Created the index, create and edit views successfully.$(tput sgr0)"
}
createViews
function controllerCrudFunctions {
echo "<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Repositories\\${repoName^}\\${repoName^}Contract;
class ${repoName^}Controller extends Controller
{
protected \$repo;
public function __construct(${repoName^}Contract \$${repoName,}Contract) {
\$this->repo = \$${repoName,}Contract;
}
public function index()
{
//
}
public function create()
{
//
}
public function store(Request \$request)
{
//
}
public function show(\$id)
{
//
}
public function edit(\$id)
{
//
}
public function update(Request \$request, \$id)
{
//
}
public function delete(\$id)
{
//
}
}" > ./app/Http/Controllers/${repoName^}Controller.php
}
controllerCrudFunctions