Skip to content

Commit

Permalink
fix #3978 (#4110)
Browse files Browse the repository at this point in the history
  • Loading branch information
IwasakiRyuichi authored Jan 10, 2025
1 parent 4ccca5c commit a8bd016
Showing 1 changed file with 22 additions and 28 deletions.
50 changes: 22 additions & 28 deletions plugins/baser-core/src/Service/ThemesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,34 +362,19 @@ public function loadDefaultDataPattern(string $currentTheme, string $dbDataPatte

return $result;
}

/**
* ヘルパーのnamespaceを変更する
* helperとnamespaceを変更する
* @checked
* @notodo
*/
public function changeHelperNameSpace($newTheme)
{
$pluginPath = BcUtil::getPluginPath($newTheme);
if (!$pluginPath) return false;
if (file_exists($pluginPath . 'src' . DS .'View' . DS .'Helper'. DS . $newTheme. 'Helper.php')) {
$helperClassPath = $pluginPath . 'src' . DS .'View' . DS .'Helper'. DS . $newTheme. 'Helper.php';
}else{
return false;
}
$file = new BcFile($helperClassPath);
$data = $file->read();
$file->write(preg_replace('/namespace .+?;/', 'namespace ' . $newTheme . '\View\Helper;', $data));
return true;
}

/**
* ヘルパーのクラス名を変更する
*/
public function ChangeHelperClassName($oldTheme,$newTheme)
public function changeHelper(string $newTheme, string $className): bool
{
$pluginPath = BcUtil::getPluginPath($newTheme);
if (!$pluginPath) return false;
$oldPath = $pluginPath . 'src'. DS .'View' . DS .'Helper' . DS . $oldTheme . 'Helper.php';
$newPath = $pluginPath . 'src'. DS .'View' . DS .'Helper' . DS . $newTheme . 'Helper.php';
$helperClassName = preg_replace('/Helper$/', '', $className) . 'CopyHelper';
$oldPath = $pluginPath . 'src'. DS .'View' . DS .'Helper' . DS . $className . '.php';
$newPath = $pluginPath . 'src'. DS .'View' . DS .'Helper' . DS . $helperClassName . '.php';
if(!file_exists($newPath))
{
if(file_exists($oldPath)) {
Expand All @@ -398,10 +383,12 @@ public function ChangeHelperClassName($oldTheme,$newTheme)
return false;
}
}
$file = new BcFile($newPath);
$data = $file->read();
$file->write(preg_replace('/class\s+.*?Helper/', 'class ' . $newTheme . 'Helper', $data));
return true;
$file = new BcFile($newPath);
$data = $file->read();
$tmpHelperNameSpace = preg_replace('/namespace .+?;/', 'namespace ' . $newTheme . '\View\Helper;', $data);
$helperNameSpace = preg_replace('/class\s+.*?Helper/', 'class ' . $helperClassName , $tmpHelperNameSpace);
$file->write($helperNameSpace);
return true;
}

/**
Expand Down Expand Up @@ -441,8 +428,15 @@ public function copy(string $theme): bool
}
BcUtil::changePluginClassName($oldTheme, $newTheme);
BcUtil::changePluginNameSpace($newTheme);
$this->ChangeHelperClassName($oldTheme,$newTheme);
$this->changeHelperNameSpace($newTheme);

$folder = new BcFolder(BASER_THEMES . $newTheme . DS . 'src' . DS . 'View' . DS . 'Helper');
$files = $folder->getFiles();

foreach($files as $file)
{
$className = basename($file, '.php');
$this->changeHelper($newTheme,$className);
}
return true;
}

Expand Down

0 comments on commit a8bd016

Please sign in to comment.