1 | <?php |
||
14 | class Renamer extends Command |
||
15 | { |
||
16 | /** |
||
17 | * {@inheritdoc} |
||
18 | */ |
||
19 | protected $signature = 'app:rename {name? : The new name}'; |
||
20 | |||
21 | /** |
||
22 | * {@inheritdoc} |
||
23 | */ |
||
24 | protected $description = 'Perform an application rename'; |
||
25 | |||
26 | /** |
||
27 | * {@inheritdoc} |
||
28 | */ |
||
29 | 1 | public function handle(): void |
|
30 | { |
||
31 | 1 | $this->alert('Renaming the application...'); |
|
32 | |||
33 | 1 | $this->rename(); |
|
34 | 1 | } |
|
35 | |||
36 | /** |
||
37 | * Perform project modifications in order to apply the |
||
38 | * application name on the composer and on the binary. |
||
39 | * |
||
40 | * @return $this |
||
41 | */ |
||
42 | 1 | protected function rename(): Renamer |
|
43 | { |
||
44 | 1 | $name = $this->asksForApplicationName(); |
|
45 | |||
46 | 1 | if (File::exists(base_path($name))) { |
|
47 | $this->error("Could't rename: Folder or file already exists."); |
||
48 | } else { |
||
49 | 1 | $this->renameBinary($name)->updateComposer($name); |
|
50 | } |
||
51 | |||
52 | 1 | return $this; |
|
53 | } |
||
54 | |||
55 | /** |
||
56 | * Display an welcome message. |
||
57 | * |
||
58 | * @return $this |
||
59 | */ |
||
60 | protected function displayWelcomeMessage(): Renamer |
||
64 | |||
65 | /** |
||
66 | * Asks for the application name. |
||
67 | * |
||
68 | * If there is no interaction, we take the folder basename. |
||
69 | * |
||
70 | * @return string |
||
71 | */ |
||
72 | 1 | protected function asksForApplicationName(): string |
|
84 | |||
85 | /** |
||
86 | * Update composer json with related information. |
||
87 | * |
||
88 | * @param string $name |
||
89 | * |
||
90 | * @return $this |
||
91 | */ |
||
92 | 1 | protected function updateComposer(string $name): Renamer |
|
104 | |||
105 | /** |
||
106 | * Renames the application binary. |
||
107 | * |
||
108 | * @param string $name |
||
109 | * |
||
110 | * @return $this |
||
111 | */ |
||
112 | 1 | protected function renameBinary(string $name): Renamer |
|
120 | |||
121 | /** |
||
122 | * Set composer file. |
||
123 | * |
||
124 | * @param string $composer |
||
125 | * |
||
126 | * @return $this |
||
127 | */ |
||
128 | 1 | protected function setComposer(string $composer): Renamer |
|
134 | |||
135 | /** |
||
136 | * Returns the current binary name. |
||
137 | * |
||
138 | * @return string |
||
139 | */ |
||
140 | 1 | protected function getCurrentBinaryName(): string |
|
146 | |||
147 | /** |
||
148 | * Get composer file. |
||
149 | * |
||
150 | * @return string |
||
151 | */ |
||
152 | 1 | protected function getComposer(): string |
|
163 | } |
||
164 |