Skip to content

Commit 5f08f55

Browse files
authored
Merge pull request #7 from Innovix-Matrix-Systems/IMS-27
Laravel Update, pint Integration and Mapper Support Added
2 parents f46fab4 + e3af065 commit 5f08f55

File tree

113 files changed

+2617
-2255
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+2617
-2255
lines changed

.husky/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env sh
22
. "$(dirname -- "$0")/_/husky.sh"
33

4-
php artisan csfixer:run
4+
php artisan pint

app/Console/Commands/GenerateCrudStarter.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public function handle()
3131
[
3232
'name' => "Api/V1/{$name}/{$name}Controller",
3333
'--api' => true,
34-
'--model' => $name
35-
]
34+
'--model' => $name,
35+
],
3636
],
3737
'request' => ['make:request', ['name' => "{$name}/{$name}InsertUpdateRequest"]],
3838
'resource' => ['make:resource', ['name' => "{$name}/{$name}Resource"]],
@@ -66,9 +66,11 @@ private function callArtisanCommand($taskName, $command, $arguments)
6666
try {
6767
$exitCode = Artisan::call($command, $arguments);
6868
$this->line(Artisan::output());
69+
6970
return $exitCode !== 0;
7071
} catch (\Exception $e) {
7172
$this->error("Error creating {$taskName}: {$e->getMessage()}");
73+
7274
return true;
7375
}
7476
}

app/Console/Commands/MakeDTOCommand.php

Lines changed: 76 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -19,113 +19,128 @@ class MakeDTOCommand extends Command
1919
/**
2020
* Name and signiture of Command.
2121
* name
22+
*
2223
* @var string
2324
*/
2425
protected $name = 'make:dto';
2526

2627
/**
2728
* command description.
2829
* description
30+
*
2931
* @var string
3032
*/
3133
protected $description = 'create a new DTO';
3234

3335
/**
34-
* Get Command argumant EX : HasAuth
35-
* getArguments
36+
* __construct
3637
*
37-
* @return array
38+
* @return void
3839
*/
39-
protected function getArguments()
40+
public function __construct()
4041
{
41-
return [
42-
['dto', InputArgument::REQUIRED, 'The name of the DTO'],
43-
];
42+
parent::__construct();
4443
}
4544

46-
4745
/**
48-
* __construct
49-
*
50-
* @return void
46+
* getClassNamespace
5147
*/
52-
public function __construct()
48+
public function getDefaultNamespace(): string
5349
{
54-
parent::__construct();
50+
return 'App\\Http\\DTOs';
5551
}
5652

5753
/**
58-
* getDTOName
54+
* Return a vaid class name
55+
* getClass
5956
*
6057
* @return string
6158
*/
62-
private function getDTOName()
59+
public function getClass()
6360
{
64-
$dto = Str::studly($this->argument('dto'));
65-
return $dto;
61+
return class_basename($this->argument($this->argumentName));
6662
}
6763

6864
/**
69-
* getDestinationFilePath
65+
* Generate class namespace dinamacally
66+
* getClassNamespace
7067
*
7168
* @return string
7269
*/
73-
protected function getDestinationFilePath()
70+
public function getClassNamespace()
7471
{
75-
return app_path() . "/Http/DTOs" . '/' . $this->getDTOName() . '.php';
72+
$extra = str_replace($this->getClass(), '', $this->argument($this->argumentName));
73+
74+
$extra = str_replace('/', '\\', $extra);
75+
76+
$namespace = $this->getDefaultNamespace();
77+
78+
$namespace .= '\\' . $extra;
79+
80+
$namespace = str_replace('/', '\\', $namespace);
81+
82+
return trim($namespace, '\\');
7683
}
7784

7885
/**
79-
* getDTONameWithoutNamespace
80-
*
81-
* @return string
86+
* Create view directory if not exists.
8287
*/
83-
private function getDTONameWithoutNamespace()
88+
public function createDir($path)
8489
{
85-
return class_basename($this->getDTOName());
90+
$dir = dirname($path);
91+
92+
if (! file_exists($dir)) {
93+
mkdir($dir, 0777, true);
94+
}
8695
}
8796

8897
/**
89-
* getClassNamespace
98+
* Execute the console command.
9099
*
91-
* @return string
100+
* @return int
92101
*/
93-
public function getDefaultNamespace(): string
102+
public function handle()
94103
{
95-
return "App\\Http\\DTOs";
104+
$path = str_replace('\\', '/', $this->getDestinationFilePath());
105+
106+
$fileContents = $this->getTemplateContents();
107+
108+
$this->createDir($path);
109+
110+
if (File::exists($path)) {
111+
$this->error("File {$path} already exists!");
112+
113+
return 1;
114+
}
115+
116+
File::put($path, $fileContents);
117+
$this->info("DTO generated successfully! path : {$path}");
118+
119+
return 0;
120+
96121
}
97122

98123
/**
99-
* Return a vaid class name
100-
* getClass
124+
* Get Command argumant EX : HasAuth
125+
* getArguments
101126
*
102-
* @return string
127+
* @return array
103128
*/
104-
public function getClass()
129+
protected function getArguments()
105130
{
106-
return class_basename($this->argument($this->argumentName));
131+
return [
132+
['dto', InputArgument::REQUIRED, 'The name of the DTO'],
133+
];
107134
}
108135

109-
110136
/**
111-
* Generate class namespace dinamacally
112-
* getClassNamespace
137+
* getDestinationFilePath
113138
*
114139
* @return string
115140
*/
116-
public function getClassNamespace()
141+
protected function getDestinationFilePath()
117142
{
118-
$extra = str_replace($this->getClass(), '', $this->argument($this->argumentName));
119-
120-
$extra = str_replace('/', '\\', $extra);
121-
122-
$namespace = $this->getDefaultNamespace();
123-
124-
$namespace .= '\\' . $extra;
125-
126-
$namespace = str_replace('/', '\\', $namespace);
127-
128-
return trim($namespace, '\\');
143+
return app_path() . '/Http/DTOs' . '/' . $this->getDTOName() . '.php';
129144
}
130145

131146
/**
@@ -136,6 +151,7 @@ public function getClassNamespace()
136151
protected function getStubFilePath()
137152
{
138153
$stub = '/stubs/dto.stub';
154+
139155
return $stub;
140156
}
141157

@@ -149,8 +165,8 @@ protected function getTemplateContents()
149165
$fileTemplate = file_get_contents(__DIR__ . $this->getStubFilePath());
150166

151167
$replaceOptions = [
152-
'CLASS_NAMESPACE' => $this->getClassNamespace(),
153-
'CLASS' => $this->getDTONameWithoutNamespace()
168+
'CLASS_NAMESPACE' => $this->getClassNamespace(),
169+
'CLASS' => $this->getDTONameWithoutNamespace(),
154170
];
155171

156172
foreach ($replaceOptions as $search => $replace) {
@@ -161,40 +177,24 @@ protected function getTemplateContents()
161177
}
162178

163179
/**
164-
* Create view directory if not exists.
180+
* getDTOName
165181
*
166-
* @param $path
182+
* @return string
167183
*/
168-
public function createDir($path)
184+
private function getDTOName()
169185
{
170-
$dir = dirname($path);
186+
$dto = Str::studly($this->argument('dto'));
171187

172-
if (!file_exists($dir)) {
173-
mkdir($dir, 0777, true);
174-
}
188+
return $dto;
175189
}
176190

177191
/**
178-
* Execute the console command.
192+
* getDTONameWithoutNamespace
179193
*
180-
* @return int
194+
* @return string
181195
*/
182-
public function handle()
196+
private function getDTONameWithoutNamespace()
183197
{
184-
$path = str_replace('\\', '/', $this->getDestinationFilePath());
185-
186-
$fileContents = $this->getTemplateContents();
187-
188-
$this->createDir($path);
189-
190-
if (File::exists($path)) {
191-
$this->error("File {$path} already exists!");
192-
return 1;
193-
}
194-
195-
File::put($path, $fileContents);
196-
$this->info("DTO generated successfully! path : {$path}");
197-
return 0;
198-
198+
return class_basename($this->getDTOName());
199199
}
200200
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use Illuminate\Console\Command;
6+
use Illuminate\Support\Facades\File;
7+
use Illuminate\Support\Str;
8+
use Symfony\Component\Console\Input\InputArgument;
9+
10+
class MakeMapperCommand extends Command
11+
{
12+
protected $name = 'make:mapper';
13+
14+
protected $description = 'Create a new mapper class';
15+
16+
protected string $argumentName = 'mapper';
17+
18+
public function __construct()
19+
{
20+
parent::__construct();
21+
}
22+
23+
public function getDefaultNamespace(): string
24+
{
25+
return 'App\\Http\\Mappers';
26+
}
27+
28+
public function getClass(): string
29+
{
30+
return class_basename($this->argument($this->argumentName));
31+
}
32+
33+
public function getClassNamespace(): string
34+
{
35+
$extra = str_replace($this->getClass(), '', $this->argument($this->argumentName));
36+
$extra = str_replace('/', '\\', $extra);
37+
$namespace = $this->getDefaultNamespace() . '\\' . $extra;
38+
39+
return trim(str_replace('/', '\\', $namespace), '\\');
40+
}
41+
42+
public function handle()
43+
{
44+
$path = str_replace('\\', '/', $this->getDestinationFilePath());
45+
$fileContents = $this->getTemplateContents();
46+
47+
$this->createDir($path);
48+
49+
if (File::exists($path)) {
50+
$this->error("File {$path} already exists!");
51+
52+
return 1;
53+
}
54+
55+
File::put($path, $fileContents);
56+
$this->info("Mapper generated successfully! path : {$path}");
57+
58+
return 0;
59+
}
60+
61+
protected function getArguments(): array
62+
{
63+
return [
64+
[$this->argumentName, InputArgument::REQUIRED, 'The name of the mapper class.'],
65+
];
66+
}
67+
68+
protected function getDestinationFilePath(): string
69+
{
70+
return app_path() . '/Http/Mappers/' . $this->getMapperName() . '.php';
71+
}
72+
73+
protected function getStubFilePath(): string
74+
{
75+
return '/stubs/mappers.stub';
76+
}
77+
78+
protected function getTemplateContents(): string
79+
{
80+
$template = file_get_contents(__DIR__ . $this->getStubFilePath());
81+
82+
$replaceOptions = [
83+
'CLASS_NAMESPACE' => $this->getClassNamespace(),
84+
'CLASS' => $this->getMapperNameWithoutNamespace(),
85+
];
86+
87+
foreach ($replaceOptions as $search => $replace) {
88+
$template = str_replace('$' . strtoupper($search) . '$', $replace, $template);
89+
}
90+
91+
return $template;
92+
}
93+
94+
protected function getMapperName(): string
95+
{
96+
$mapper = Str::studly($this->argument($this->argumentName));
97+
98+
if (! Str::endsWith(strtolower($mapper), 'mapper')) {
99+
$mapper .= 'Mapper';
100+
}
101+
102+
return $mapper;
103+
}
104+
105+
protected function getMapperNameWithoutNamespace(): string
106+
{
107+
return class_basename($this->getMapperName());
108+
}
109+
110+
protected function createDir(string $path)
111+
{
112+
$dir = dirname($path);
113+
if (! file_exists($dir)) {
114+
mkdir($dir, 0777, true);
115+
}
116+
}
117+
}

0 commit comments

Comments
 (0)