Skip to content

Commit

Permalink
Merge branch '5.1.x' of github.com:baserproject/basercms into 5.1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuring committed Jan 10, 2025
2 parents ff353b0 + a8bd016 commit c2792fa
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions plugins/baser-core/src/Service/ThemesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use Cake\Routing\Router;
use Cake\Utility\Inflector;
use Laminas\Diactoros\UploadedFile;
use BaserCore\Utility\BcFile;

/**
* ThemesService
Expand Down Expand Up @@ -361,6 +362,34 @@ public function loadDefaultDataPattern(string $currentTheme, string $dbDataPatte

return $result;
}
/**
* helperとnamespaceを変更する
* @checked
* @notodo
*/

public function changeHelper(string $newTheme, string $className): bool
{
$pluginPath = BcUtil::getPluginPath($newTheme);
if (!$pluginPath) return false;
$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)) {
rename($oldPath, $newPath);
} else {
return false;
}
}
$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 @@ -399,6 +428,15 @@ public function copy(string $theme): bool
}
BcUtil::changePluginClassName($oldTheme, $newTheme);
BcUtil::changePluginNameSpace($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 c2792fa

Please sign in to comment.