Skip to content

Commit 7d4cb34

Browse files
authored
Merge pull request #371 from kenjis/fix-setup
Improve setup
2 parents c48cb81 + 4d6cdcc commit 7d4cb34

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

docs/install.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class Auth extends ShieldAuth
117117
}
118118
```
119119

120-
2. **Helper Setup** The `setting` helper needs to be included in almost every page. The simplest way to do this is to add them to the `BaseController::initController` method:
120+
2. **Helper Setup** The `setting` helper needs to be included in almost every page. The simplest way to do this is to add it to the `BaseController::initController` method:
121121

122122
```php
123123
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)

src/Commands/Setup.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,12 @@ protected function add(string $file, string $code, string $pattern, string $repl
196196
}
197197

198198
/**
199+
* Replace for setupHelper()
200+
*
199201
* @param string $file Relative file path like 'Controllers/BaseController.php'.
200202
* @param array $replaces [search => replace]
201203
*/
202-
protected function replace(string $file, array $replaces): void
204+
private function replace(string $file, array $replaces): bool
203205
{
204206
$path = $this->distPath . $file;
205207
$cleanPath = clean_path($path);
@@ -209,16 +211,18 @@ protected function replace(string $file, array $replaces): void
209211
$output = $this->replacer->replace($content, $replaces);
210212

211213
if ($output === $content) {
212-
CLI::error(" Skipped {$cleanPath}. It has already been updated.");
213-
214-
return;
214+
return false;
215215
}
216216

217217
if (write_file($path, $output)) {
218218
CLI::write(CLI::color(' Updated: ', 'green') . $cleanPath);
219-
} else {
220-
CLI::error(" Error updating {$cleanPath}.");
219+
220+
return true;
221221
}
222+
223+
CLI::error(" Error updating {$cleanPath}.");
224+
225+
return false;
222226
}
223227

224228
private function setupHelper(): void
@@ -230,7 +234,9 @@ private function setupHelper(): void
230234
$replaces = [
231235
'$this->helpers = array_merge($this->helpers, [\'auth\', \'setting\']);' => $check,
232236
];
233-
$this->replace($file, $replaces);
237+
if ($this->replace($file, $replaces)) {
238+
return;
239+
}
234240

235241
// Add helper setup
236242
$pattern = '/(' . preg_quote('// Do Not Edit This Line', '/') . ')/u';

0 commit comments

Comments
 (0)