@@ -10,38 +10,38 @@ |
||
10 | 10 | |
11 | 11 | class PushNotificationDeviceService extends BaseService |
12 | 12 | { |
13 | - /** |
|
14 | - * Init new object. |
|
15 | - * |
|
16 | - * @param PushNotificationDeviceRepository $repo |
|
17 | - * @return void |
|
18 | - */ |
|
19 | - public function __construct(PushNotificationDeviceRepository $repo) |
|
20 | - { |
|
21 | - parent::__construct($repo); |
|
22 | - } |
|
13 | + /** |
|
14 | + * Init new object. |
|
15 | + * |
|
16 | + * @param PushNotificationDeviceRepository $repo |
|
17 | + * @return void |
|
18 | + */ |
|
19 | + public function __construct(PushNotificationDeviceRepository $repo) |
|
20 | + { |
|
21 | + parent::__construct($repo); |
|
22 | + } |
|
23 | 23 | |
24 | - /** |
|
25 | - * Register the given device to the logged in user. |
|
26 | - * |
|
27 | - * @param array $data |
|
28 | - * @return void |
|
29 | - */ |
|
30 | - public function registerDevice($data) |
|
31 | - { |
|
32 | - $data['access_token'] = \Auth::user()->token(); |
|
33 | - $data['user_id'] = \Auth::id(); |
|
34 | - $device = $this->repo->first([ |
|
35 | - 'and' => [ |
|
36 | - 'device_token' => $data['device_token'], |
|
37 | - 'user_id' => $data['user_id'] |
|
38 | - ] |
|
39 | - ]); |
|
24 | + /** |
|
25 | + * Register the given device to the logged in user. |
|
26 | + * |
|
27 | + * @param array $data |
|
28 | + * @return void |
|
29 | + */ |
|
30 | + public function registerDevice($data) |
|
31 | + { |
|
32 | + $data['access_token'] = \Auth::user()->token(); |
|
33 | + $data['user_id'] = \Auth::id(); |
|
34 | + $device = $this->repo->first([ |
|
35 | + 'and' => [ |
|
36 | + 'device_token' => $data['device_token'], |
|
37 | + 'user_id' => $data['user_id'] |
|
38 | + ] |
|
39 | + ]); |
|
40 | 40 | |
41 | - if ($device) { |
|
42 | - $data['id'] = $device->id; |
|
43 | - } |
|
41 | + if ($device) { |
|
42 | + $data['id'] = $device->id; |
|
43 | + } |
|
44 | 44 | |
45 | - return $this->repo->save($data); |
|
46 | - } |
|
45 | + return $this->repo->save($data); |
|
46 | + } |
|
47 | 47 | } |
@@ -7,64 +7,64 @@ |
||
7 | 7 | |
8 | 8 | class OauthClientRepository extends BaseRepository |
9 | 9 | { |
10 | - /** |
|
11 | - * Init new object. |
|
12 | - * |
|
13 | - * @param OauthClient $model |
|
14 | - * @return void |
|
15 | - */ |
|
16 | - public function __construct(OauthClient $model) |
|
17 | - { |
|
18 | - parent::__construct($model); |
|
19 | - } |
|
10 | + /** |
|
11 | + * Init new object. |
|
12 | + * |
|
13 | + * @param OauthClient $model |
|
14 | + * @return void |
|
15 | + */ |
|
16 | + public function __construct(OauthClient $model) |
|
17 | + { |
|
18 | + parent::__construct($model); |
|
19 | + } |
|
20 | 20 | |
21 | - /** |
|
22 | - * Revoke the given client tokens. |
|
23 | - * |
|
24 | - * @param mixed $client |
|
25 | - * @return void |
|
26 | - */ |
|
27 | - public function revokeClientTokens($client) |
|
28 | - { |
|
29 | - $client = ! filter_var($client, FILTER_VALIDATE_INT) ? $client : $this->find($client); |
|
30 | - $client->tokens()->update(['revoked' => true]); |
|
31 | - } |
|
21 | + /** |
|
22 | + * Revoke the given client tokens. |
|
23 | + * |
|
24 | + * @param mixed $client |
|
25 | + * @return void |
|
26 | + */ |
|
27 | + public function revokeClientTokens($client) |
|
28 | + { |
|
29 | + $client = ! filter_var($client, FILTER_VALIDATE_INT) ? $client : $this->find($client); |
|
30 | + $client->tokens()->update(['revoked' => true]); |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * Ensure access token hasn't expired or revoked. |
|
35 | - * |
|
36 | - * @param string $accessToken |
|
37 | - * @return boolean |
|
38 | - */ |
|
39 | - public function accessTokenExpiredOrRevoked($accessToken) |
|
40 | - { |
|
41 | - $accessTokenId = json_decode($accessToken, true)['id']; |
|
42 | - $accessToken = \DB::table('oauth_access_tokens') |
|
43 | - ->where('id', $accessTokenId) |
|
44 | - ->first(); |
|
33 | + /** |
|
34 | + * Ensure access token hasn't expired or revoked. |
|
35 | + * |
|
36 | + * @param string $accessToken |
|
37 | + * @return boolean |
|
38 | + */ |
|
39 | + public function accessTokenExpiredOrRevoked($accessToken) |
|
40 | + { |
|
41 | + $accessTokenId = json_decode($accessToken, true)['id']; |
|
42 | + $accessToken = \DB::table('oauth_access_tokens') |
|
43 | + ->where('id', $accessTokenId) |
|
44 | + ->first(); |
|
45 | 45 | |
46 | - if (\Carbon\Carbon::parse($accessToken->expires_at)->isPast() || $accessToken->revoked) { |
|
47 | - return true; |
|
48 | - } |
|
46 | + if (\Carbon\Carbon::parse($accessToken->expires_at)->isPast() || $accessToken->revoked) { |
|
47 | + return true; |
|
48 | + } |
|
49 | 49 | |
50 | - return false; |
|
51 | - } |
|
50 | + return false; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Revoke the given access token and all |
|
55 | - * associated refresh tokens. |
|
56 | - * |
|
57 | - * @param oject $accessToken |
|
58 | - * @return void |
|
59 | - */ |
|
60 | - public function revokeAccessToken($accessToken) |
|
61 | - { |
|
62 | - \DB::table('oauth_refresh_tokens') |
|
63 | - ->where('access_token_id', $accessToken->id) |
|
64 | - ->update([ |
|
65 | - 'revoked' => true |
|
66 | - ]); |
|
53 | + /** |
|
54 | + * Revoke the given access token and all |
|
55 | + * associated refresh tokens. |
|
56 | + * |
|
57 | + * @param oject $accessToken |
|
58 | + * @return void |
|
59 | + */ |
|
60 | + public function revokeAccessToken($accessToken) |
|
61 | + { |
|
62 | + \DB::table('oauth_refresh_tokens') |
|
63 | + ->where('access_token_id', $accessToken->id) |
|
64 | + ->update([ |
|
65 | + 'revoked' => true |
|
66 | + ]); |
|
67 | 67 | |
68 | - $accessToken->revoke(); |
|
69 | - } |
|
68 | + $accessToken->revoke(); |
|
69 | + } |
|
70 | 70 | } |
@@ -6,30 +6,30 @@ |
||
6 | 6 | |
7 | 7 | class Core implements BaseFactoryInterface |
8 | 8 | { |
9 | - /** |
|
10 | - * Construct the repository class name based on |
|
11 | - * the method name called, search in the |
|
12 | - * given namespaces for the class and |
|
13 | - * return an instance. |
|
14 | - * |
|
15 | - * @param string $name the called method name |
|
16 | - * @param array $arguments the method arguments |
|
17 | - * @return object |
|
18 | - */ |
|
19 | - public function __call($name, $arguments) |
|
20 | - { |
|
21 | - foreach (\Module::all() as $module) { |
|
22 | - $nameSpace = 'App\\Modules\\' . $module['basename'] ; |
|
23 | - $model = ucfirst(\Str::singular($name)); |
|
24 | - if(count($arguments) == 1 && $arguments[0]) { |
|
25 | - $class = $nameSpace . '\\Services\\' . $model . 'Service'; |
|
26 | - } else { |
|
27 | - $class = $nameSpace . '\\Repositories\\' . $model . 'Repository'; |
|
28 | - } |
|
9 | + /** |
|
10 | + * Construct the repository class name based on |
|
11 | + * the method name called, search in the |
|
12 | + * given namespaces for the class and |
|
13 | + * return an instance. |
|
14 | + * |
|
15 | + * @param string $name the called method name |
|
16 | + * @param array $arguments the method arguments |
|
17 | + * @return object |
|
18 | + */ |
|
19 | + public function __call($name, $arguments) |
|
20 | + { |
|
21 | + foreach (\Module::all() as $module) { |
|
22 | + $nameSpace = 'App\\Modules\\' . $module['basename'] ; |
|
23 | + $model = ucfirst(\Str::singular($name)); |
|
24 | + if(count($arguments) == 1 && $arguments[0]) { |
|
25 | + $class = $nameSpace . '\\Services\\' . $model . 'Service'; |
|
26 | + } else { |
|
27 | + $class = $nameSpace . '\\Repositories\\' . $model . 'Repository'; |
|
28 | + } |
|
29 | 29 | |
30 | - if (class_exists($class)) { |
|
31 | - return \App::make($class); |
|
32 | - } |
|
33 | - } |
|
34 | - } |
|
30 | + if (class_exists($class)) { |
|
31 | + return \App::make($class); |
|
32 | + } |
|
33 | + } |
|
34 | + } |
|
35 | 35 | } |
@@ -4,46 +4,46 @@ |
||
4 | 4 | |
5 | 5 | trait Translatable |
6 | 6 | { |
7 | - /** |
|
8 | - * Create a new model instance that is existing. |
|
9 | - * |
|
10 | - * @param array $attributes |
|
11 | - * @param string|null $connection |
|
12 | - * @return static |
|
13 | - */ |
|
14 | - public function newFromBuilder($attributes = [], $connection = null) |
|
15 | - { |
|
16 | - $model = parent::newFromBuilder($attributes, $connection); |
|
17 | - |
|
18 | - foreach ($model->attributes as $key => $value) { |
|
19 | - if (isset($this->translatable) && in_array($key, $this->translatable)) { |
|
20 | - $model->$key = $this->getTranslatedAttribute($value); |
|
21 | - } |
|
22 | - } |
|
23 | - |
|
24 | - return $model; |
|
25 | - } |
|
26 | - |
|
27 | - /** |
|
28 | - * Returns a translatable model attribute based on the application's locale settings. |
|
29 | - * |
|
30 | - * @param $values |
|
31 | - * @return string |
|
32 | - */ |
|
33 | - protected function getTranslatedAttribute($values) |
|
34 | - { |
|
35 | - $values = json_decode($values); |
|
36 | - $primaryLocale = \Session::get('locale'); |
|
37 | - $fallbackLocale = 'en'; |
|
38 | - |
|
39 | - if ($primaryLocale == 'all') { |
|
40 | - return $values; |
|
41 | - } |
|
42 | - |
|
43 | - if (! $primaryLocale || ! is_object($values) || ! property_exists($values, $primaryLocale)) { |
|
44 | - return $values ? (isset($values->$fallbackLocale) ? $values->$fallbackLocale : $values) : ''; |
|
45 | - } |
|
46 | - |
|
47 | - return $primaryLocale == 'all' ? $values : $values->$primaryLocale; |
|
48 | - } |
|
7 | + /** |
|
8 | + * Create a new model instance that is existing. |
|
9 | + * |
|
10 | + * @param array $attributes |
|
11 | + * @param string|null $connection |
|
12 | + * @return static |
|
13 | + */ |
|
14 | + public function newFromBuilder($attributes = [], $connection = null) |
|
15 | + { |
|
16 | + $model = parent::newFromBuilder($attributes, $connection); |
|
17 | + |
|
18 | + foreach ($model->attributes as $key => $value) { |
|
19 | + if (isset($this->translatable) && in_array($key, $this->translatable)) { |
|
20 | + $model->$key = $this->getTranslatedAttribute($value); |
|
21 | + } |
|
22 | + } |
|
23 | + |
|
24 | + return $model; |
|
25 | + } |
|
26 | + |
|
27 | + /** |
|
28 | + * Returns a translatable model attribute based on the application's locale settings. |
|
29 | + * |
|
30 | + * @param $values |
|
31 | + * @return string |
|
32 | + */ |
|
33 | + protected function getTranslatedAttribute($values) |
|
34 | + { |
|
35 | + $values = json_decode($values); |
|
36 | + $primaryLocale = \Session::get('locale'); |
|
37 | + $fallbackLocale = 'en'; |
|
38 | + |
|
39 | + if ($primaryLocale == 'all') { |
|
40 | + return $values; |
|
41 | + } |
|
42 | + |
|
43 | + if (! $primaryLocale || ! is_object($values) || ! property_exists($values, $primaryLocale)) { |
|
44 | + return $values ? (isset($values->$fallbackLocale) ? $values->$fallbackLocale : $values) : ''; |
|
45 | + } |
|
46 | + |
|
47 | + return $primaryLocale == 'all' ? $values : $values->$primaryLocale; |
|
48 | + } |
|
49 | 49 | } |
@@ -13,8 +13,8 @@ |
||
13 | 13 | |
14 | 14 | Route::group(['prefix' => 'settings'], function () { |
15 | 15 | |
16 | - Route::get('/', 'SettingController@index'); |
|
17 | - Route::get('{id}', 'SettingController@show'); |
|
18 | - Route::patch('{id}', 'SettingController@update'); |
|
19 | - Route::post('save/many', 'SettingController@saveMany'); |
|
16 | + Route::get('/', 'SettingController@index'); |
|
17 | + Route::get('{id}', 'SettingController@show'); |
|
18 | + Route::patch('{id}', 'SettingController@update'); |
|
19 | + Route::post('save/many', 'SettingController@saveMany'); |
|
20 | 20 | }); |
@@ -5,14 +5,14 @@ |
||
5 | 5 | |
6 | 6 | class DummyRepository extends BaseRepository |
7 | 7 | { |
8 | - /** |
|
9 | - * Init new object. |
|
10 | - * |
|
11 | - * @param DummyModel $model |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function __construct(DummyModel $model) |
|
15 | - { |
|
16 | - parent::__construct($model); |
|
17 | - } |
|
8 | + /** |
|
9 | + * Init new object. |
|
10 | + * |
|
11 | + * @param DummyModel $model |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function __construct(DummyModel $model) |
|
15 | + { |
|
16 | + parent::__construct($model); |
|
17 | + } |
|
18 | 18 | } |
@@ -2,8 +2,8 @@ |
||
2 | 2 | |
3 | 3 | return [ |
4 | 4 | |
5 | - /** |
|
6 | - * Here goes your error messages. |
|
7 | - */ |
|
5 | + /** |
|
6 | + * Here goes your error messages. |
|
7 | + */ |
|
8 | 8 | |
9 | 9 | ]; |
@@ -2,8 +2,8 @@ |
||
2 | 2 | |
3 | 3 | return [ |
4 | 4 | |
5 | - /** |
|
6 | - * Here goes your error messages. |
|
7 | - */ |
|
5 | + /** |
|
6 | + * Here goes your error messages. |
|
7 | + */ |
|
8 | 8 | |
9 | 9 | ]; |
@@ -10,244 +10,244 @@ |
||
10 | 10 | |
11 | 11 | class MakeModuleCommand extends Command |
12 | 12 | { |
13 | - /** |
|
14 | - * The name and signature of the console command. |
|
15 | - * |
|
16 | - * @var string |
|
17 | - */ |
|
18 | - protected $signature = 'generate:module |
|
13 | + /** |
|
14 | + * The name and signature of the console command. |
|
15 | + * |
|
16 | + * @var string |
|
17 | + */ |
|
18 | + protected $signature = 'generate:module |
|
19 | 19 | {slug : The slug of the module}'; |
20 | 20 | |
21 | - /** |
|
22 | - * The console command description. |
|
23 | - * |
|
24 | - * @var string |
|
25 | - */ |
|
26 | - protected $description = 'Create a new module'; |
|
27 | - |
|
28 | - /** |
|
29 | - * The modules instance. |
|
30 | - * |
|
31 | - * @var RepositoryManager |
|
32 | - */ |
|
33 | - protected $module; |
|
34 | - |
|
35 | - /** |
|
36 | - * The filesystem instance. |
|
37 | - * |
|
38 | - * @var Filesystem |
|
39 | - */ |
|
40 | - protected $files; |
|
41 | - |
|
42 | - /** |
|
43 | - * Array to store the configuration details. |
|
44 | - * |
|
45 | - * @var array |
|
46 | - */ |
|
47 | - protected $container; |
|
48 | - |
|
49 | - /** |
|
50 | - * Array of folder mappings. |
|
51 | - * |
|
52 | - * @var Array |
|
53 | - */ |
|
54 | - protected $mapping = [ |
|
55 | - 'Database/Factories' => 'Database/Factories', |
|
56 | - 'Database/Migrations' => 'Database/Migrations', |
|
57 | - 'Database/Seeds' => 'Database/Seeds', |
|
58 | - 'Http/Controllers' => 'Http/Controllers', |
|
59 | - 'Http/Requests' => 'Http/Requests', |
|
60 | - 'Http/Resources' => 'Http/Resources', |
|
61 | - 'ModelObservers' => 'ModelObservers', |
|
62 | - 'Providers' => 'Providers', |
|
63 | - 'Repositories' => 'Repositories', |
|
64 | - 'Services' => 'Services', |
|
65 | - 'Routes' => 'Routes', |
|
66 | - 'Errors' => 'Errors', |
|
67 | - 'Resources' => 'Resources', |
|
68 | - ]; |
|
69 | - |
|
70 | - /** |
|
71 | - * Create a new command instance. |
|
72 | - * |
|
73 | - * @param Filesystem $files |
|
74 | - * @param RepositoryManager $module |
|
75 | - */ |
|
76 | - public function __construct(Filesystem $files, RepositoryManager $module) |
|
77 | - { |
|
78 | - parent::__construct(); |
|
79 | - |
|
80 | - $this->files = $files; |
|
81 | - $this->module = $module; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Execute the console command. |
|
86 | - * |
|
87 | - * @return mixed |
|
88 | - */ |
|
89 | - public function handle() |
|
90 | - { |
|
91 | - $this->container['slug'] = Str::slug($this->argument('slug')); |
|
92 | - $this->container['name'] = Str::studly($this->container['slug']); |
|
93 | - $this->container['version'] = '1.0'; |
|
94 | - $this->container['description'] = 'This is the description for the ' . $this->container['name'] . ' module.'; |
|
95 | - $this->container['location'] = config('modules.default_location'); |
|
96 | - $this->container['provider'] = config("modules.locations.{$this->container['location']}.provider"); |
|
97 | - $this->container['basename'] = Str::studly($this->container['slug']); |
|
98 | - $this->container['namespace'] = config("modules.locations.{$this->container['location']}.namespace").$this->container['basename']; |
|
99 | - |
|
100 | - return $this->generate(); |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Generate the module. |
|
105 | - */ |
|
106 | - protected function generate() |
|
107 | - { |
|
108 | - $steps = [ |
|
109 | - 'Generating module...' => 'generateModule', |
|
110 | - 'Optimizing module cache...' => 'optimizeModules', |
|
111 | - 'Generating migrations...' => 'generateMigration', |
|
112 | - ]; |
|
113 | - |
|
114 | - $progress = new ProgressBar($this->output, count($steps)); |
|
115 | - $progress->start(); |
|
116 | - |
|
117 | - foreach ($steps as $message => $function) { |
|
118 | - $progress->setMessage($message); |
|
119 | - |
|
120 | - $this->$function(); |
|
121 | - |
|
122 | - $progress->advance(); |
|
123 | - } |
|
124 | - |
|
125 | - $progress->finish(); |
|
126 | - |
|
127 | - event($this->container['slug'] . '.module.made'); |
|
128 | - |
|
129 | - $this->info("\nModule generated successfully."); |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * Generate defined module folders. |
|
134 | - */ |
|
135 | - protected function generateModule() |
|
136 | - { |
|
137 | - $location = $this->container['location']; |
|
138 | - $root = module_path(null, '', $location); |
|
139 | - $manifest = config("modules.locations.$location.manifest") ?: 'module.json'; |
|
140 | - $provider = config("modules.locations.$location.provider") ?: 'ModuleServiceProvider'; |
|
141 | - |
|
142 | - if (!$this->files->isDirectory($root)) { |
|
143 | - $this->files->makeDirectory($root); |
|
144 | - } |
|
145 | - |
|
146 | - $directory = module_path(null, $this->container['basename'], $location); |
|
147 | - $source = __DIR__ . '/Stubs/Module'; |
|
148 | - |
|
149 | - $this->files->makeDirectory($directory); |
|
150 | - |
|
151 | - $sourceFiles = $this->files->allFiles($source, true); |
|
152 | - |
|
153 | - if (!empty($this->mapping)) { |
|
154 | - $search = array_keys($this->mapping); |
|
155 | - $replace = array_values($this->mapping); |
|
156 | - } |
|
157 | - |
|
158 | - foreach ($sourceFiles as $file) { |
|
159 | - $contents = $this->replacePlaceholders($file->getContents()); |
|
160 | - $subPath = $file->getRelativePathname(); |
|
161 | - |
|
162 | - if (!empty($this->mapping)) { |
|
163 | - $subPath = str_replace($search, $replace, $subPath); |
|
164 | - } |
|
165 | - |
|
166 | - $filePath = $directory . '/' . $subPath; |
|
21 | + /** |
|
22 | + * The console command description. |
|
23 | + * |
|
24 | + * @var string |
|
25 | + */ |
|
26 | + protected $description = 'Create a new module'; |
|
27 | + |
|
28 | + /** |
|
29 | + * The modules instance. |
|
30 | + * |
|
31 | + * @var RepositoryManager |
|
32 | + */ |
|
33 | + protected $module; |
|
34 | + |
|
35 | + /** |
|
36 | + * The filesystem instance. |
|
37 | + * |
|
38 | + * @var Filesystem |
|
39 | + */ |
|
40 | + protected $files; |
|
41 | + |
|
42 | + /** |
|
43 | + * Array to store the configuration details. |
|
44 | + * |
|
45 | + * @var array |
|
46 | + */ |
|
47 | + protected $container; |
|
48 | + |
|
49 | + /** |
|
50 | + * Array of folder mappings. |
|
51 | + * |
|
52 | + * @var Array |
|
53 | + */ |
|
54 | + protected $mapping = [ |
|
55 | + 'Database/Factories' => 'Database/Factories', |
|
56 | + 'Database/Migrations' => 'Database/Migrations', |
|
57 | + 'Database/Seeds' => 'Database/Seeds', |
|
58 | + 'Http/Controllers' => 'Http/Controllers', |
|
59 | + 'Http/Requests' => 'Http/Requests', |
|
60 | + 'Http/Resources' => 'Http/Resources', |
|
61 | + 'ModelObservers' => 'ModelObservers', |
|
62 | + 'Providers' => 'Providers', |
|
63 | + 'Repositories' => 'Repositories', |
|
64 | + 'Services' => 'Services', |
|
65 | + 'Routes' => 'Routes', |
|
66 | + 'Errors' => 'Errors', |
|
67 | + 'Resources' => 'Resources', |
|
68 | + ]; |
|
69 | + |
|
70 | + /** |
|
71 | + * Create a new command instance. |
|
72 | + * |
|
73 | + * @param Filesystem $files |
|
74 | + * @param RepositoryManager $module |
|
75 | + */ |
|
76 | + public function __construct(Filesystem $files, RepositoryManager $module) |
|
77 | + { |
|
78 | + parent::__construct(); |
|
79 | + |
|
80 | + $this->files = $files; |
|
81 | + $this->module = $module; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Execute the console command. |
|
86 | + * |
|
87 | + * @return mixed |
|
88 | + */ |
|
89 | + public function handle() |
|
90 | + { |
|
91 | + $this->container['slug'] = Str::slug($this->argument('slug')); |
|
92 | + $this->container['name'] = Str::studly($this->container['slug']); |
|
93 | + $this->container['version'] = '1.0'; |
|
94 | + $this->container['description'] = 'This is the description for the ' . $this->container['name'] . ' module.'; |
|
95 | + $this->container['location'] = config('modules.default_location'); |
|
96 | + $this->container['provider'] = config("modules.locations.{$this->container['location']}.provider"); |
|
97 | + $this->container['basename'] = Str::studly($this->container['slug']); |
|
98 | + $this->container['namespace'] = config("modules.locations.{$this->container['location']}.namespace").$this->container['basename']; |
|
99 | + |
|
100 | + return $this->generate(); |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Generate the module. |
|
105 | + */ |
|
106 | + protected function generate() |
|
107 | + { |
|
108 | + $steps = [ |
|
109 | + 'Generating module...' => 'generateModule', |
|
110 | + 'Optimizing module cache...' => 'optimizeModules', |
|
111 | + 'Generating migrations...' => 'generateMigration', |
|
112 | + ]; |
|
113 | + |
|
114 | + $progress = new ProgressBar($this->output, count($steps)); |
|
115 | + $progress->start(); |
|
116 | + |
|
117 | + foreach ($steps as $message => $function) { |
|
118 | + $progress->setMessage($message); |
|
119 | + |
|
120 | + $this->$function(); |
|
121 | + |
|
122 | + $progress->advance(); |
|
123 | + } |
|
124 | + |
|
125 | + $progress->finish(); |
|
126 | + |
|
127 | + event($this->container['slug'] . '.module.made'); |
|
128 | + |
|
129 | + $this->info("\nModule generated successfully."); |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * Generate defined module folders. |
|
134 | + */ |
|
135 | + protected function generateModule() |
|
136 | + { |
|
137 | + $location = $this->container['location']; |
|
138 | + $root = module_path(null, '', $location); |
|
139 | + $manifest = config("modules.locations.$location.manifest") ?: 'module.json'; |
|
140 | + $provider = config("modules.locations.$location.provider") ?: 'ModuleServiceProvider'; |
|
141 | + |
|
142 | + if (!$this->files->isDirectory($root)) { |
|
143 | + $this->files->makeDirectory($root); |
|
144 | + } |
|
145 | + |
|
146 | + $directory = module_path(null, $this->container['basename'], $location); |
|
147 | + $source = __DIR__ . '/Stubs/Module'; |
|
148 | + |
|
149 | + $this->files->makeDirectory($directory); |
|
150 | + |
|
151 | + $sourceFiles = $this->files->allFiles($source, true); |
|
152 | + |
|
153 | + if (!empty($this->mapping)) { |
|
154 | + $search = array_keys($this->mapping); |
|
155 | + $replace = array_values($this->mapping); |
|
156 | + } |
|
157 | + |
|
158 | + foreach ($sourceFiles as $file) { |
|
159 | + $contents = $this->replacePlaceholders($file->getContents()); |
|
160 | + $subPath = $file->getRelativePathname(); |
|
161 | + |
|
162 | + if (!empty($this->mapping)) { |
|
163 | + $subPath = str_replace($search, $replace, $subPath); |
|
164 | + } |
|
165 | + |
|
166 | + $filePath = $directory . '/' . $subPath; |
|
167 | 167 | |
168 | - // if the file is module.json, replace it with the custom manifest file name |
|
169 | - if ($file->getFilename() === 'module.json' && $manifest) { |
|
170 | - $filePath = str_replace('module.json', $manifest, $filePath); |
|
171 | - } |
|
168 | + // if the file is module.json, replace it with the custom manifest file name |
|
169 | + if ($file->getFilename() === 'module.json' && $manifest) { |
|
170 | + $filePath = str_replace('module.json', $manifest, $filePath); |
|
171 | + } |
|
172 | 172 | |
173 | - // if the file is ModuleServiceProvider.php, replace it with the custom provider file name |
|
174 | - if ($file->getFilename() === 'ModuleServiceProvider.php') { |
|
175 | - $filePath = str_replace('ModuleServiceProvider', $provider, $filePath); |
|
176 | - } |
|
177 | - $filePath = $this->replacePlaceholders($filePath); |
|
173 | + // if the file is ModuleServiceProvider.php, replace it with the custom provider file name |
|
174 | + if ($file->getFilename() === 'ModuleServiceProvider.php') { |
|
175 | + $filePath = str_replace('ModuleServiceProvider', $provider, $filePath); |
|
176 | + } |
|
177 | + $filePath = $this->replacePlaceholders($filePath); |
|
178 | 178 | |
179 | - $dir = dirname($filePath); |
|
179 | + $dir = dirname($filePath); |
|
180 | 180 | |
181 | - if (! $this->files->isDirectory($dir)) { |
|
182 | - $this->files->makeDirectory($dir, 0755, true); |
|
183 | - } |
|
184 | - |
|
185 | - $this->files->put($filePath, $contents); |
|
186 | - } |
|
187 | - } |
|
188 | - |
|
189 | - protected function replacePlaceholders($contents) |
|
190 | - { |
|
191 | - $modelName = \Str::camel($this->container['slug']); |
|
192 | - $modelNameSingular = \Str::singular($modelName); |
|
193 | - |
|
194 | - $find = [ |
|
195 | - 'DummyFactory', |
|
196 | - 'DummyModelName', |
|
197 | - 'DummyModuleSlug', |
|
198 | - 'DummyModule', |
|
199 | - 'DummyModel', |
|
200 | - 'DummyDatabaseSeeder', |
|
201 | - 'DummyTableSeeder', |
|
202 | - 'DummyController', |
|
203 | - 'DummyService', |
|
204 | - 'DummyRepository', |
|
205 | - 'DummyErrors', |
|
206 | - 'StoreDummy', |
|
207 | - 'DummyResource', |
|
208 | - 'DummyObserver', |
|
209 | - 'DummyTableName', |
|
210 | - 'DummyRoutePrefix', |
|
211 | - ]; |
|
212 | - |
|
213 | - $replace = [ |
|
214 | - ucfirst($modelNameSingular) . 'Factory', |
|
215 | - $modelNameSingular, |
|
216 | - $this->container['slug'], |
|
217 | - ucfirst($modelName), |
|
218 | - ucfirst($modelNameSingular), |
|
219 | - ucfirst($modelName) . 'DatabaseSeeder', |
|
220 | - ucfirst($modelName) . 'TableSeeder', |
|
221 | - ucfirst($modelNameSingular) . 'Controller', |
|
222 | - ucfirst($modelNameSingular) . 'Service', |
|
223 | - ucfirst($modelNameSingular) . 'Repository', |
|
224 | - ucfirst($modelName) . 'Errors', |
|
225 | - 'Store' . ucfirst($modelNameSingular), |
|
226 | - ucfirst($modelNameSingular), |
|
227 | - ucfirst($modelNameSingular) . 'Observer', |
|
228 | - \Str::snake($modelName), |
|
229 | - $modelName, |
|
230 | - ]; |
|
231 | - |
|
232 | - return str_replace($find, $replace, $contents); |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * Reset module cache of enabled and disabled modules. |
|
237 | - */ |
|
238 | - protected function optimizeModules() |
|
239 | - { |
|
240 | - return $this->callSilent('module:optimize'); |
|
241 | - } |
|
242 | - |
|
243 | - /** |
|
244 | - * Generate table migrations. |
|
245 | - */ |
|
246 | - protected function generateMigration() |
|
247 | - { |
|
248 | - $modelName = $this->container['slug']; |
|
249 | - $migrationName = \Str::camel($modelName); |
|
250 | - $migrationName = \Str::snake($migrationName); |
|
251 | - return $this->callSilent('make:module:migration', ['slug' => $modelName, 'name' => 'create_' . $migrationName . '_table']); |
|
252 | - } |
|
181 | + if (! $this->files->isDirectory($dir)) { |
|
182 | + $this->files->makeDirectory($dir, 0755, true); |
|
183 | + } |
|
184 | + |
|
185 | + $this->files->put($filePath, $contents); |
|
186 | + } |
|
187 | + } |
|
188 | + |
|
189 | + protected function replacePlaceholders($contents) |
|
190 | + { |
|
191 | + $modelName = \Str::camel($this->container['slug']); |
|
192 | + $modelNameSingular = \Str::singular($modelName); |
|
193 | + |
|
194 | + $find = [ |
|
195 | + 'DummyFactory', |
|
196 | + 'DummyModelName', |
|
197 | + 'DummyModuleSlug', |
|
198 | + 'DummyModule', |
|
199 | + 'DummyModel', |
|
200 | + 'DummyDatabaseSeeder', |
|
201 | + 'DummyTableSeeder', |
|
202 | + 'DummyController', |
|
203 | + 'DummyService', |
|
204 | + 'DummyRepository', |
|
205 | + 'DummyErrors', |
|
206 | + 'StoreDummy', |
|
207 | + 'DummyResource', |
|
208 | + 'DummyObserver', |
|
209 | + 'DummyTableName', |
|
210 | + 'DummyRoutePrefix', |
|
211 | + ]; |
|
212 | + |
|
213 | + $replace = [ |
|
214 | + ucfirst($modelNameSingular) . 'Factory', |
|
215 | + $modelNameSingular, |
|
216 | + $this->container['slug'], |
|
217 | + ucfirst($modelName), |
|
218 | + ucfirst($modelNameSingular), |
|
219 | + ucfirst($modelName) . 'DatabaseSeeder', |
|
220 | + ucfirst($modelName) . 'TableSeeder', |
|
221 | + ucfirst($modelNameSingular) . 'Controller', |
|
222 | + ucfirst($modelNameSingular) . 'Service', |
|
223 | + ucfirst($modelNameSingular) . 'Repository', |
|
224 | + ucfirst($modelName) . 'Errors', |
|
225 | + 'Store' . ucfirst($modelNameSingular), |
|
226 | + ucfirst($modelNameSingular), |
|
227 | + ucfirst($modelNameSingular) . 'Observer', |
|
228 | + \Str::snake($modelName), |
|
229 | + $modelName, |
|
230 | + ]; |
|
231 | + |
|
232 | + return str_replace($find, $replace, $contents); |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * Reset module cache of enabled and disabled modules. |
|
237 | + */ |
|
238 | + protected function optimizeModules() |
|
239 | + { |
|
240 | + return $this->callSilent('module:optimize'); |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * Generate table migrations. |
|
245 | + */ |
|
246 | + protected function generateMigration() |
|
247 | + { |
|
248 | + $modelName = $this->container['slug']; |
|
249 | + $migrationName = \Str::camel($modelName); |
|
250 | + $migrationName = \Str::snake($migrationName); |
|
251 | + return $this->callSilent('make:module:migration', ['slug' => $modelName, 'name' => 'create_' . $migrationName . '_table']); |
|
252 | + } |
|
253 | 253 | } |