@@ -6,58 +6,58 @@ |
||
6 | 6 | |
7 | 7 | class BaseEnum |
8 | 8 | { |
9 | - /** |
|
10 | - * Get all constants as an array. |
|
11 | - * |
|
12 | - * @return array |
|
13 | - */ |
|
14 | - public static function all() |
|
15 | - { |
|
16 | - return (new ReflectionClass(get_called_class()))->getConstants(); |
|
17 | - } |
|
18 | - |
|
19 | - /** |
|
20 | - * Get all constants values as an array. |
|
21 | - * |
|
22 | - * @return array |
|
23 | - */ |
|
24 | - public static function values() |
|
25 | - { |
|
26 | - return array_values(self::all()); |
|
27 | - } |
|
28 | - |
|
29 | - /** |
|
30 | - * Get all constants keys as an array. |
|
31 | - * |
|
32 | - * @return array |
|
33 | - */ |
|
34 | - public static function keys() |
|
35 | - { |
|
36 | - return array_keys(self::all()); |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * Get constant key for the given value. |
|
41 | - * |
|
42 | - * @return mixed |
|
43 | - */ |
|
44 | - public static function key($type) |
|
45 | - { |
|
46 | - return collect(self::all())->search($type); |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * Convert the consts to key: value comma seperated string. |
|
51 | - * |
|
52 | - * @return string |
|
53 | - */ |
|
54 | - public static function toString() |
|
55 | - { |
|
56 | - $stringArr = []; |
|
57 | - collect(self::all())->each(function ($item, $key) use (&$stringArr) { |
|
58 | - $stringArr[] = $key . ': ' . $item; |
|
59 | - }); |
|
60 | - |
|
61 | - return implode(',', $stringArr); |
|
62 | - } |
|
9 | + /** |
|
10 | + * Get all constants as an array. |
|
11 | + * |
|
12 | + * @return array |
|
13 | + */ |
|
14 | + public static function all() |
|
15 | + { |
|
16 | + return (new ReflectionClass(get_called_class()))->getConstants(); |
|
17 | + } |
|
18 | + |
|
19 | + /** |
|
20 | + * Get all constants values as an array. |
|
21 | + * |
|
22 | + * @return array |
|
23 | + */ |
|
24 | + public static function values() |
|
25 | + { |
|
26 | + return array_values(self::all()); |
|
27 | + } |
|
28 | + |
|
29 | + /** |
|
30 | + * Get all constants keys as an array. |
|
31 | + * |
|
32 | + * @return array |
|
33 | + */ |
|
34 | + public static function keys() |
|
35 | + { |
|
36 | + return array_keys(self::all()); |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * Get constant key for the given value. |
|
41 | + * |
|
42 | + * @return mixed |
|
43 | + */ |
|
44 | + public static function key($type) |
|
45 | + { |
|
46 | + return collect(self::all())->search($type); |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * Convert the consts to key: value comma seperated string. |
|
51 | + * |
|
52 | + * @return string |
|
53 | + */ |
|
54 | + public static function toString() |
|
55 | + { |
|
56 | + $stringArr = []; |
|
57 | + collect(self::all())->each(function ($item, $key) use (&$stringArr) { |
|
58 | + $stringArr[] = $key . ': ' . $item; |
|
59 | + }); |
|
60 | + |
|
61 | + return implode(',', $stringArr); |
|
62 | + } |
|
63 | 63 | } |
@@ -54,8 +54,8 @@ |
||
54 | 54 | public static function toString() |
55 | 55 | { |
56 | 56 | $stringArr = []; |
57 | - collect(self::all())->each(function ($item, $key) use (&$stringArr) { |
|
58 | - $stringArr[] = $key . ': ' . $item; |
|
57 | + collect(self::all())->each(function($item, $key) use (&$stringArr) { |
|
58 | + $stringArr[] = $key.': '.$item; |
|
59 | 59 | }); |
60 | 60 | |
61 | 61 | return implode(',', $stringArr); |
@@ -13,112 +13,112 @@ |
||
13 | 13 | |
14 | 14 | class BaseApiController extends Controller |
15 | 15 | { |
16 | - /** |
|
17 | - * Array of eager loaded relations. |
|
18 | - * |
|
19 | - * @var array |
|
20 | - */ |
|
21 | - protected $relations; |
|
16 | + /** |
|
17 | + * Array of eager loaded relations. |
|
18 | + * |
|
19 | + * @var array |
|
20 | + */ |
|
21 | + protected $relations; |
|
22 | 22 | |
23 | - /** |
|
24 | - * @var BaseServiceInterface |
|
25 | - */ |
|
26 | - protected $service; |
|
23 | + /** |
|
24 | + * @var BaseServiceInterface |
|
25 | + */ |
|
26 | + protected $service; |
|
27 | 27 | |
28 | - /** |
|
29 | - * Path of the model resource. |
|
30 | - * |
|
31 | - * @var string |
|
32 | - */ |
|
33 | - protected $modelResource; |
|
28 | + /** |
|
29 | + * Path of the model resource. |
|
30 | + * |
|
31 | + * @var string |
|
32 | + */ |
|
33 | + protected $modelResource; |
|
34 | 34 | |
35 | - /** |
|
36 | - * Path of the sotre form request. |
|
37 | - * |
|
38 | - * @var string |
|
39 | - */ |
|
40 | - protected $storeFormRequest; |
|
35 | + /** |
|
36 | + * Path of the sotre form request. |
|
37 | + * |
|
38 | + * @var string |
|
39 | + */ |
|
40 | + protected $storeFormRequest; |
|
41 | 41 | |
42 | - /** |
|
43 | - * Init new object. |
|
44 | - * |
|
45 | - * @param BaseServiceInterface $service |
|
46 | - * @return void |
|
47 | - */ |
|
48 | - public function __construct(BaseServiceInterface $service) |
|
49 | - { |
|
50 | - $this->service = new CachingDecorator($service, App::make(Repository::class), App::make(Request::class), App::make(\Illuminate\Contracts\Session\Session::class)); |
|
51 | - } |
|
42 | + /** |
|
43 | + * Init new object. |
|
44 | + * |
|
45 | + * @param BaseServiceInterface $service |
|
46 | + * @return void |
|
47 | + */ |
|
48 | + public function __construct(BaseServiceInterface $service) |
|
49 | + { |
|
50 | + $this->service = new CachingDecorator($service, App::make(Repository::class), App::make(Request::class), App::make(\Illuminate\Contracts\Session\Session::class)); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Fetch all records with relations from storage. |
|
55 | - * |
|
56 | - * @param Request $request |
|
57 | - * @return \Illuminate\Http\Response |
|
58 | - */ |
|
59 | - public function index(Request $request) |
|
60 | - { |
|
61 | - $local = Session::get('locale') == 'all' ? 'en' : Session::get('locale'); |
|
62 | - return $this->modelResource::collection($this->service->list($local, $request->relations, $request->query(), $request->query('perPage', 15), $request->query('sortBy', 'created_at'), $request->query('desc', false), $request->query('trashed', false))); |
|
63 | - } |
|
53 | + /** |
|
54 | + * Fetch all records with relations from storage. |
|
55 | + * |
|
56 | + * @param Request $request |
|
57 | + * @return \Illuminate\Http\Response |
|
58 | + */ |
|
59 | + public function index(Request $request) |
|
60 | + { |
|
61 | + $local = Session::get('locale') == 'all' ? 'en' : Session::get('locale'); |
|
62 | + return $this->modelResource::collection($this->service->list($local, $request->relations, $request->query(), $request->query('perPage', 15), $request->query('sortBy', 'created_at'), $request->query('desc', false), $request->query('trashed', false))); |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * Fetch the single object with relations from storage. |
|
67 | - * |
|
68 | - * @param Request $request |
|
69 | - * @param integer $id Id of the requested model. |
|
70 | - * @return \Illuminate\Http\Response |
|
71 | - */ |
|
72 | - public function show(Request $request, $id) |
|
73 | - { |
|
74 | - return new $this->modelResource($this->service->find($id, $request->relations)); |
|
75 | - } |
|
65 | + /** |
|
66 | + * Fetch the single object with relations from storage. |
|
67 | + * |
|
68 | + * @param Request $request |
|
69 | + * @param integer $id Id of the requested model. |
|
70 | + * @return \Illuminate\Http\Response |
|
71 | + */ |
|
72 | + public function show(Request $request, $id) |
|
73 | + { |
|
74 | + return new $this->modelResource($this->service->find($id, $request->relations)); |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Insert the given model to storage. |
|
79 | - * |
|
80 | - * @return \Illuminate\Http\Response |
|
81 | - */ |
|
82 | - public function store() |
|
83 | - { |
|
84 | - $data = App::make($this->storeFormRequest)->validated(); |
|
85 | - Session::put('locale', 'all'); |
|
77 | + /** |
|
78 | + * Insert the given model to storage. |
|
79 | + * |
|
80 | + * @return \Illuminate\Http\Response |
|
81 | + */ |
|
82 | + public function store() |
|
83 | + { |
|
84 | + $data = App::make($this->storeFormRequest)->validated(); |
|
85 | + Session::put('locale', 'all'); |
|
86 | 86 | |
87 | - return new $this->modelResource($this->service->save($data)); |
|
88 | - } |
|
87 | + return new $this->modelResource($this->service->save($data)); |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * Update the given model to storage. |
|
92 | - * |
|
93 | - * @param integer $id |
|
94 | - * @return \Illuminate\Http\Response |
|
95 | - */ |
|
96 | - public function update($id) |
|
97 | - { |
|
98 | - $data = App::make($this->storeFormRequest)->validated(); |
|
99 | - $data['id'] = $id; |
|
100 | - return new $this->modelResource($this->service->save($data)); |
|
101 | - } |
|
90 | + /** |
|
91 | + * Update the given model to storage. |
|
92 | + * |
|
93 | + * @param integer $id |
|
94 | + * @return \Illuminate\Http\Response |
|
95 | + */ |
|
96 | + public function update($id) |
|
97 | + { |
|
98 | + $data = App::make($this->storeFormRequest)->validated(); |
|
99 | + $data['id'] = $id; |
|
100 | + return new $this->modelResource($this->service->save($data)); |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * Delete by the given id from storage. |
|
105 | - * |
|
106 | - * @param integer $id Id of the deleted model. |
|
107 | - * @return \Illuminate\Http\Response |
|
108 | - */ |
|
109 | - public function destroy($id) |
|
110 | - { |
|
111 | - return new GeneralResource($this->service->delete($id)); |
|
112 | - } |
|
103 | + /** |
|
104 | + * Delete by the given id from storage. |
|
105 | + * |
|
106 | + * @param integer $id Id of the deleted model. |
|
107 | + * @return \Illuminate\Http\Response |
|
108 | + */ |
|
109 | + public function destroy($id) |
|
110 | + { |
|
111 | + return new GeneralResource($this->service->delete($id)); |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * Restore the deleted model. |
|
116 | - * |
|
117 | - * @param integer $id Id of the restored model. |
|
118 | - * @return \Illuminate\Http\Response |
|
119 | - */ |
|
120 | - public function restore($id) |
|
121 | - { |
|
122 | - return new GeneralResource($this->service->restore($id)); |
|
123 | - } |
|
114 | + /** |
|
115 | + * Restore the deleted model. |
|
116 | + * |
|
117 | + * @param integer $id Id of the restored model. |
|
118 | + * @return \Illuminate\Http\Response |
|
119 | + */ |
|
120 | + public function restore($id) |
|
121 | + { |
|
122 | + return new GeneralResource($this->service->restore($id)); |
|
123 | + } |
|
124 | 124 | } |
@@ -10,248 +10,248 @@ |
||
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 | - 'DummyServiceInterface', |
|
205 | - 'DummyRepository', |
|
206 | - 'DummyRepositoryInterface', |
|
207 | - 'DummyErrors', |
|
208 | - 'StoreDummy', |
|
209 | - 'DummyResource', |
|
210 | - 'DummyObserver', |
|
211 | - 'DummyTableName', |
|
212 | - 'DummyRoutePrefix', |
|
213 | - ]; |
|
214 | - |
|
215 | - $replace = [ |
|
216 | - ucfirst($modelNameSingular) . 'Factory', |
|
217 | - $modelNameSingular, |
|
218 | - $this->container['slug'], |
|
219 | - ucfirst($modelName), |
|
220 | - ucfirst($modelNameSingular), |
|
221 | - ucfirst($modelName) . 'DatabaseSeeder', |
|
222 | - ucfirst($modelName) . 'TableSeeder', |
|
223 | - ucfirst($modelNameSingular) . 'Controller', |
|
224 | - ucfirst($modelNameSingular) . 'Service', |
|
225 | - ucfirst($modelNameSingular) . 'ServiceInterface', |
|
226 | - ucfirst($modelNameSingular) . 'Repository', |
|
227 | - ucfirst($modelNameSingular) . 'RepositoryInterface', |
|
228 | - ucfirst($modelName) . 'Errors', |
|
229 | - 'Store' . ucfirst($modelNameSingular), |
|
230 | - ucfirst($modelNameSingular), |
|
231 | - ucfirst($modelNameSingular) . 'Observer', |
|
232 | - Str::snake($modelName), |
|
233 | - $modelName, |
|
234 | - ]; |
|
235 | - |
|
236 | - return str_replace($find, $replace, $contents); |
|
237 | - } |
|
238 | - |
|
239 | - /** |
|
240 | - * Reset module cache of enabled and disabled modules. |
|
241 | - */ |
|
242 | - protected function optimizeModules() |
|
243 | - { |
|
244 | - return $this->callSilent('module:optimize'); |
|
245 | - } |
|
246 | - |
|
247 | - /** |
|
248 | - * Generate table migrations. |
|
249 | - */ |
|
250 | - protected function generateMigration() |
|
251 | - { |
|
252 | - $modelName = $this->container['slug']; |
|
253 | - $migrationName = Str::camel($modelName); |
|
254 | - $migrationName = Str::snake($migrationName); |
|
255 | - return $this->callSilent('make:module:migration', ['slug' => $modelName, 'name' => 'create_' . $migrationName . '_table']); |
|
256 | - } |
|
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 | + 'DummyServiceInterface', |
|
205 | + 'DummyRepository', |
|
206 | + 'DummyRepositoryInterface', |
|
207 | + 'DummyErrors', |
|
208 | + 'StoreDummy', |
|
209 | + 'DummyResource', |
|
210 | + 'DummyObserver', |
|
211 | + 'DummyTableName', |
|
212 | + 'DummyRoutePrefix', |
|
213 | + ]; |
|
214 | + |
|
215 | + $replace = [ |
|
216 | + ucfirst($modelNameSingular) . 'Factory', |
|
217 | + $modelNameSingular, |
|
218 | + $this->container['slug'], |
|
219 | + ucfirst($modelName), |
|
220 | + ucfirst($modelNameSingular), |
|
221 | + ucfirst($modelName) . 'DatabaseSeeder', |
|
222 | + ucfirst($modelName) . 'TableSeeder', |
|
223 | + ucfirst($modelNameSingular) . 'Controller', |
|
224 | + ucfirst($modelNameSingular) . 'Service', |
|
225 | + ucfirst($modelNameSingular) . 'ServiceInterface', |
|
226 | + ucfirst($modelNameSingular) . 'Repository', |
|
227 | + ucfirst($modelNameSingular) . 'RepositoryInterface', |
|
228 | + ucfirst($modelName) . 'Errors', |
|
229 | + 'Store' . ucfirst($modelNameSingular), |
|
230 | + ucfirst($modelNameSingular), |
|
231 | + ucfirst($modelNameSingular) . 'Observer', |
|
232 | + Str::snake($modelName), |
|
233 | + $modelName, |
|
234 | + ]; |
|
235 | + |
|
236 | + return str_replace($find, $replace, $contents); |
|
237 | + } |
|
238 | + |
|
239 | + /** |
|
240 | + * Reset module cache of enabled and disabled modules. |
|
241 | + */ |
|
242 | + protected function optimizeModules() |
|
243 | + { |
|
244 | + return $this->callSilent('module:optimize'); |
|
245 | + } |
|
246 | + |
|
247 | + /** |
|
248 | + * Generate table migrations. |
|
249 | + */ |
|
250 | + protected function generateMigration() |
|
251 | + { |
|
252 | + $modelName = $this->container['slug']; |
|
253 | + $migrationName = Str::camel($modelName); |
|
254 | + $migrationName = Str::snake($migrationName); |
|
255 | + return $this->callSilent('make:module:migration', ['slug' => $modelName, 'name' => 'create_' . $migrationName . '_table']); |
|
256 | + } |
|
257 | 257 | } |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | $this->container['slug'] = Str::slug($this->argument('slug')); |
92 | 92 | $this->container['name'] = Str::studly($this->container['slug']); |
93 | 93 | $this->container['version'] = '1.0'; |
94 | - $this->container['description'] = 'This is the description for the ' . $this->container['name'] . ' module.'; |
|
94 | + $this->container['description'] = 'This is the description for the '.$this->container['name'].' module.'; |
|
95 | 95 | $this->container['location'] = config('modules.default_location'); |
96 | 96 | $this->container['provider'] = config("modules.locations.{$this->container['location']}.provider"); |
97 | 97 | $this->container['basename'] = Str::studly($this->container['slug']); |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | |
125 | 125 | $progress->finish(); |
126 | 126 | |
127 | - event($this->container['slug'] . '.module.made'); |
|
127 | + event($this->container['slug'].'.module.made'); |
|
128 | 128 | |
129 | 129 | $this->info("\nModule generated successfully."); |
130 | 130 | } |
@@ -139,18 +139,18 @@ discard block |
||
139 | 139 | $manifest = config("modules.locations.$location.manifest") ?: 'module.json'; |
140 | 140 | $provider = config("modules.locations.$location.provider") ?: 'ModuleServiceProvider'; |
141 | 141 | |
142 | - if (!$this->files->isDirectory($root)) { |
|
142 | + if ( ! $this->files->isDirectory($root)) { |
|
143 | 143 | $this->files->makeDirectory($root); |
144 | 144 | } |
145 | 145 | |
146 | 146 | $directory = module_path(null, $this->container['basename'], $location); |
147 | - $source = __DIR__ . '/Stubs/Module'; |
|
147 | + $source = __DIR__.'/Stubs/Module'; |
|
148 | 148 | |
149 | 149 | $this->files->makeDirectory($directory); |
150 | 150 | |
151 | 151 | $sourceFiles = $this->files->allFiles($source, true); |
152 | 152 | |
153 | - if (!empty($this->mapping)) { |
|
153 | + if ( ! empty($this->mapping)) { |
|
154 | 154 | $search = array_keys($this->mapping); |
155 | 155 | $replace = array_values($this->mapping); |
156 | 156 | } |
@@ -159,11 +159,11 @@ discard block |
||
159 | 159 | $contents = $this->replacePlaceholders($file->getContents()); |
160 | 160 | $subPath = $file->getRelativePathname(); |
161 | 161 | |
162 | - if (!empty($this->mapping)) { |
|
162 | + if ( ! empty($this->mapping)) { |
|
163 | 163 | $subPath = str_replace($search, $replace, $subPath); |
164 | 164 | } |
165 | 165 | |
166 | - $filePath = $directory . '/' . $subPath; |
|
166 | + $filePath = $directory.'/'.$subPath; |
|
167 | 167 | |
168 | 168 | // if the file is module.json, replace it with the custom manifest file name |
169 | 169 | if ($file->getFilename() === 'module.json' && $manifest) { |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | |
179 | 179 | $dir = dirname($filePath); |
180 | 180 | |
181 | - if (! $this->files->isDirectory($dir)) { |
|
181 | + if ( ! $this->files->isDirectory($dir)) { |
|
182 | 182 | $this->files->makeDirectory($dir, 0755, true); |
183 | 183 | } |
184 | 184 | |
@@ -213,22 +213,22 @@ discard block |
||
213 | 213 | ]; |
214 | 214 | |
215 | 215 | $replace = [ |
216 | - ucfirst($modelNameSingular) . 'Factory', |
|
216 | + ucfirst($modelNameSingular).'Factory', |
|
217 | 217 | $modelNameSingular, |
218 | 218 | $this->container['slug'], |
219 | 219 | ucfirst($modelName), |
220 | 220 | ucfirst($modelNameSingular), |
221 | - ucfirst($modelName) . 'DatabaseSeeder', |
|
222 | - ucfirst($modelName) . 'TableSeeder', |
|
223 | - ucfirst($modelNameSingular) . 'Controller', |
|
224 | - ucfirst($modelNameSingular) . 'Service', |
|
225 | - ucfirst($modelNameSingular) . 'ServiceInterface', |
|
226 | - ucfirst($modelNameSingular) . 'Repository', |
|
227 | - ucfirst($modelNameSingular) . 'RepositoryInterface', |
|
228 | - ucfirst($modelName) . 'Errors', |
|
229 | - 'Store' . ucfirst($modelNameSingular), |
|
221 | + ucfirst($modelName).'DatabaseSeeder', |
|
222 | + ucfirst($modelName).'TableSeeder', |
|
223 | + ucfirst($modelNameSingular).'Controller', |
|
224 | + ucfirst($modelNameSingular).'Service', |
|
225 | + ucfirst($modelNameSingular).'ServiceInterface', |
|
226 | + ucfirst($modelNameSingular).'Repository', |
|
227 | + ucfirst($modelNameSingular).'RepositoryInterface', |
|
228 | + ucfirst($modelName).'Errors', |
|
229 | + 'Store'.ucfirst($modelNameSingular), |
|
230 | 230 | ucfirst($modelNameSingular), |
231 | - ucfirst($modelNameSingular) . 'Observer', |
|
231 | + ucfirst($modelNameSingular).'Observer', |
|
232 | 232 | Str::snake($modelName), |
233 | 233 | $modelName, |
234 | 234 | ]; |
@@ -252,6 +252,6 @@ discard block |
||
252 | 252 | $modelName = $this->container['slug']; |
253 | 253 | $migrationName = Str::camel($modelName); |
254 | 254 | $migrationName = Str::snake($migrationName); |
255 | - return $this->callSilent('make:module:migration', ['slug' => $modelName, 'name' => 'create_' . $migrationName . '_table']); |
|
255 | + return $this->callSilent('make:module:migration', ['slug' => $modelName, 'name' => 'create_'.$migrationName.'_table']); |
|
256 | 256 | } |
257 | 257 | } |
@@ -7,14 +7,14 @@ |
||
7 | 7 | |
8 | 8 | class DummyRepository extends BaseRepository implements DummyRepositoryInterface |
9 | 9 | { |
10 | - /** |
|
11 | - * Init new object. |
|
12 | - * |
|
13 | - * @param DummyModel $model |
|
14 | - * @return void |
|
15 | - */ |
|
16 | - public function __construct(DummyModel $model) |
|
17 | - { |
|
18 | - parent::__construct($model); |
|
19 | - } |
|
10 | + /** |
|
11 | + * Init new object. |
|
12 | + * |
|
13 | + * @param DummyModel $model |
|
14 | + * @return void |
|
15 | + */ |
|
16 | + public function __construct(DummyModel $model) |
|
17 | + { |
|
18 | + parent::__construct($model); |
|
19 | + } |
|
20 | 20 | } |
@@ -7,42 +7,42 @@ |
||
7 | 7 | |
8 | 8 | class DummyController extends BaseApiController |
9 | 9 | { |
10 | - /** |
|
11 | - * Path of the sotre form request. |
|
12 | - * |
|
13 | - * @var string |
|
14 | - */ |
|
15 | - protected $storeFormRequest = 'App\Modules\DummyModule\Http\Requests\StoreDummy'; |
|
10 | + /** |
|
11 | + * Path of the sotre form request. |
|
12 | + * |
|
13 | + * @var string |
|
14 | + */ |
|
15 | + protected $storeFormRequest = 'App\Modules\DummyModule\Http\Requests\StoreDummy'; |
|
16 | 16 | |
17 | - /** |
|
18 | - * Path of the model resource |
|
19 | - * |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - protected $modelResource = 'App\Modules\DummyModule\Http\Resources\DummyModel'; |
|
17 | + /** |
|
18 | + * Path of the model resource |
|
19 | + * |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + protected $modelResource = 'App\Modules\DummyModule\Http\Resources\DummyModel'; |
|
23 | 23 | |
24 | - /** |
|
25 | - * List of all route actions that the base api controller |
|
26 | - * will skip permissions check for them. |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $skipPermissionCheck = []; |
|
24 | + /** |
|
25 | + * List of all route actions that the base api controller |
|
26 | + * will skip permissions check for them. |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected $skipPermissionCheck = []; |
|
30 | 30 | |
31 | - /** |
|
32 | - * List of all route actions that the base api controller |
|
33 | - * will skip login check for them. |
|
34 | - * @var array |
|
35 | - */ |
|
36 | - protected $skipLoginCheck = []; |
|
31 | + /** |
|
32 | + * List of all route actions that the base api controller |
|
33 | + * will skip login check for them. |
|
34 | + * @var array |
|
35 | + */ |
|
36 | + protected $skipLoginCheck = []; |
|
37 | 37 | |
38 | - /** |
|
39 | - * Init new object. |
|
40 | - * |
|
41 | - * @param DummyServiceInterface $service |
|
42 | - * @return void |
|
43 | - */ |
|
44 | - public function __construct(DummyServiceInterface $service) |
|
45 | - { |
|
46 | - parent::__construct($service); |
|
47 | - } |
|
38 | + /** |
|
39 | + * Init new object. |
|
40 | + * |
|
41 | + * @param DummyServiceInterface $service |
|
42 | + * @return void |
|
43 | + */ |
|
44 | + public function __construct(DummyServiceInterface $service) |
|
45 | + { |
|
46 | + parent::__construct($service); |
|
47 | + } |
|
48 | 48 | } |
@@ -7,14 +7,14 @@ |
||
7 | 7 | |
8 | 8 | class DummyService extends BaseService implements DummyServiceInterface |
9 | 9 | { |
10 | - /** |
|
11 | - * Init new object. |
|
12 | - * |
|
13 | - * @param DummyRepositoryInterface $repo |
|
14 | - * @return void |
|
15 | - */ |
|
16 | - public function __construct(DummyRepositoryInterface $repo) |
|
17 | - { |
|
18 | - parent::__construct($repo); |
|
19 | - } |
|
10 | + /** |
|
11 | + * Init new object. |
|
12 | + * |
|
13 | + * @param DummyRepositoryInterface $repo |
|
14 | + * @return void |
|
15 | + */ |
|
16 | + public function __construct(DummyRepositoryInterface $repo) |
|
17 | + { |
|
18 | + parent::__construct($repo); |
|
19 | + } |
|
20 | 20 | } |
@@ -10,35 +10,35 @@ |
||
10 | 10 | |
11 | 11 | class ModuleServiceProvider extends ServiceProvider |
12 | 12 | { |
13 | - /** |
|
14 | - * Bootstrap the module services. |
|
15 | - * |
|
16 | - * @return void |
|
17 | - */ |
|
18 | - public function boot() |
|
19 | - { |
|
20 | - $this->loadTranslationsFrom(__DIR__.'/../Resources/Lang', 'DummyModuleSlug'); |
|
21 | - $this->loadViewsFrom(__DIR__.'/../Resources/Views', 'DummyModuleSlug'); |
|
13 | + /** |
|
14 | + * Bootstrap the module services. |
|
15 | + * |
|
16 | + * @return void |
|
17 | + */ |
|
18 | + public function boot() |
|
19 | + { |
|
20 | + $this->loadTranslationsFrom(__DIR__.'/../Resources/Lang', 'DummyModuleSlug'); |
|
21 | + $this->loadViewsFrom(__DIR__.'/../Resources/Views', 'DummyModuleSlug'); |
|
22 | 22 | |
23 | - $this->loadMigrationsFrom(module_path('DummyModuleSlug', 'Database/Migrations', 'app')); |
|
24 | - if (!$this->app->configurationIsCached()) { |
|
25 | - $this->loadConfigsFrom(module_path('DummyModuleSlug', 'Config', 'app')); |
|
26 | - } |
|
27 | - } |
|
23 | + $this->loadMigrationsFrom(module_path('DummyModuleSlug', 'Database/Migrations', 'app')); |
|
24 | + if (!$this->app->configurationIsCached()) { |
|
25 | + $this->loadConfigsFrom(module_path('DummyModuleSlug', 'Config', 'app')); |
|
26 | + } |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * Register the module services. |
|
31 | - * |
|
32 | - * @return void |
|
33 | - */ |
|
34 | - public function register() |
|
35 | - { |
|
36 | - $this->app->register(RouteServiceProvider::class); |
|
29 | + /** |
|
30 | + * Register the module services. |
|
31 | + * |
|
32 | + * @return void |
|
33 | + */ |
|
34 | + public function register() |
|
35 | + { |
|
36 | + $this->app->register(RouteServiceProvider::class); |
|
37 | 37 | |
38 | - /** |
|
39 | - * Bind interfaces to implmentations. |
|
40 | - */ |
|
41 | - $this->app->bind(DummyServiceInterface::class, DummyService::class); |
|
42 | - $this->app->bind(DummyRepositoryInterface::class, DummyRepository::class); |
|
43 | - } |
|
38 | + /** |
|
39 | + * Bind interfaces to implmentations. |
|
40 | + */ |
|
41 | + $this->app->bind(DummyServiceInterface::class, DummyService::class); |
|
42 | + $this->app->bind(DummyRepositoryInterface::class, DummyRepository::class); |
|
43 | + } |
|
44 | 44 | } |
@@ -6,5 +6,5 @@ |
||
6 | 6 | |
7 | 7 | interface SettingServiceInterface extends BaseServiceInterface |
8 | 8 | { |
9 | - public function saveMany(array $data): void; |
|
9 | + public function saveMany(array $data): void; |
|
10 | 10 | } |
@@ -8,29 +8,29 @@ |
||
8 | 8 | |
9 | 9 | class SettingService extends BaseService implements SettingServiceInterface |
10 | 10 | { |
11 | - /** |
|
12 | - * Init new object. |
|
13 | - * |
|
14 | - * @param SettingRepositoryInterface $repo |
|
15 | - * @return void |
|
16 | - */ |
|
17 | - public function __construct(SettingRepositoryInterface $repo) |
|
18 | - { |
|
19 | - parent::__construct($repo); |
|
20 | - } |
|
11 | + /** |
|
12 | + * Init new object. |
|
13 | + * |
|
14 | + * @param SettingRepositoryInterface $repo |
|
15 | + * @return void |
|
16 | + */ |
|
17 | + public function __construct(SettingRepositoryInterface $repo) |
|
18 | + { |
|
19 | + parent::__construct($repo); |
|
20 | + } |
|
21 | 21 | |
22 | - /** |
|
23 | - * Save list of settings. |
|
24 | - * |
|
25 | - * @param array $data |
|
26 | - * @return void |
|
27 | - */ |
|
28 | - public function saveMany(array $data): void |
|
29 | - { |
|
30 | - DB::transaction(function () use ($data) { |
|
31 | - foreach ($data as $value) { |
|
32 | - $this->repo->save($value); |
|
33 | - } |
|
34 | - }); |
|
35 | - } |
|
22 | + /** |
|
23 | + * Save list of settings. |
|
24 | + * |
|
25 | + * @param array $data |
|
26 | + * @return void |
|
27 | + */ |
|
28 | + public function saveMany(array $data): void |
|
29 | + { |
|
30 | + DB::transaction(function () use ($data) { |
|
31 | + foreach ($data as $value) { |
|
32 | + $this->repo->save($value); |
|
33 | + } |
|
34 | + }); |
|
35 | + } |
|
36 | 36 | } |
@@ -27,7 +27,7 @@ |
||
27 | 27 | */ |
28 | 28 | public function saveMany(array $data): void |
29 | 29 | { |
30 | - DB::transaction(function () use ($data) { |
|
30 | + DB::transaction(function() use ($data) { |
|
31 | 31 | foreach ($data as $value) { |
32 | 32 | $this->repo->save($value); |
33 | 33 | } |