|
32 | 32 | use Cake\Routing\Router; |
33 | 33 | use Cake\Utility\Inflector; |
34 | 34 | use Laminas\Diactoros\UploadedFile; |
| 35 | +use BaserCore\Utility\BcFile; |
35 | 36 |
|
36 | 37 | /** |
37 | 38 | * ThemesService |
@@ -362,6 +363,47 @@ public function loadDefaultDataPattern(string $currentTheme, string $dbDataPatte |
362 | 363 | return $result; |
363 | 364 | } |
364 | 365 |
|
| 366 | + /** |
| 367 | + * ヘルパーのnamespaceを変更する |
| 368 | + */ |
| 369 | + public function changeHelperNameSpace($newTheme) |
| 370 | + { |
| 371 | + $pluginPath = BcUtil::getPluginPath($newTheme); |
| 372 | + if (!$pluginPath) return false; |
| 373 | + if (file_exists($pluginPath . 'src' . DS .'View' . DS .'Helper'. DS . $newTheme. 'Helper.php')) { |
| 374 | + $helperClassPath = $pluginPath . 'src' . DS .'View' . DS .'Helper'. DS . $newTheme. 'Helper.php'; |
| 375 | + }else{ |
| 376 | + return false; |
| 377 | + } |
| 378 | + $file = new BcFile($helperClassPath); |
| 379 | + $data = $file->read(); |
| 380 | + $file->write(preg_replace('/namespace .+?;/', 'namespace ' . $newTheme . '\View\Helper;', $data)); |
| 381 | + return true; |
| 382 | + } |
| 383 | + |
| 384 | + /** |
| 385 | + * ヘルパーのクラス名を変更する |
| 386 | + */ |
| 387 | + public function ChangeHelperClassName($oldTheme,$newTheme) |
| 388 | + { |
| 389 | + $pluginPath = BcUtil::getPluginPath($newTheme); |
| 390 | + if (!$pluginPath) return false; |
| 391 | + $oldPath = $pluginPath . 'src'. DS .'View' . DS .'Helper' . DS . $oldTheme . 'Helper.php'; |
| 392 | + $newPath = $pluginPath . 'src'. DS .'View' . DS .'Helper' . DS . $newTheme . 'Helper.php'; |
| 393 | + if(!file_exists($newPath)) |
| 394 | + { |
| 395 | + if(file_exists($oldPath)) { |
| 396 | + rename($oldPath, $newPath); |
| 397 | + } else { |
| 398 | + return false; |
| 399 | + } |
| 400 | + } |
| 401 | + $file = new BcFile($newPath); |
| 402 | + $data = $file->read(); |
| 403 | + $file->write(preg_replace('/class\s+.*?Helper/', 'class ' . $newTheme . 'Helper', $data)); |
| 404 | + return true; |
| 405 | + } |
| 406 | + |
365 | 407 | /** |
366 | 408 | * コピーする |
367 | 409 | * |
@@ -399,6 +441,8 @@ public function copy(string $theme): bool |
399 | 441 | } |
400 | 442 | BcUtil::changePluginClassName($oldTheme, $newTheme); |
401 | 443 | BcUtil::changePluginNameSpace($newTheme); |
| 444 | + $this->ChangeHelperClassName($oldTheme,$newTheme); |
| 445 | + $this->changeHelperNameSpace($newTheme); |
402 | 446 | return true; |
403 | 447 | } |
404 | 448 |
|
|
0 commit comments