@@ -362,34 +362,19 @@ public function loadDefaultDataPattern(string $currentTheme, string $dbDataPatte
362362
363363 return $ result ;
364364 }
365-
366365 /**
367- * ヘルパーのnamespaceを変更する
366+ * helperとnamespaceを変更する
367+ * @checked
368+ * @notodo
368369 */
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- }
383370
384- /**
385- * ヘルパーのクラス名を変更する
386- */
387- public function ChangeHelperClassName ($ oldTheme ,$ newTheme )
371+ public function changeHelper (string $ newTheme , string $ className ): bool
388372 {
389373 $ pluginPath = BcUtil::getPluginPath ($ newTheme );
390374 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 ' ;
375+ $ helperClassName = preg_replace ('/Helper$/ ' , '' , $ className ) . 'CopyHelper ' ;
376+ $ oldPath = $ pluginPath . 'src ' . DS .'View ' . DS .'Helper ' . DS . $ className . '.php ' ;
377+ $ newPath = $ pluginPath . 'src ' . DS .'View ' . DS .'Helper ' . DS . $ helperClassName . '.php ' ;
393378 if (!file_exists ($ newPath ))
394379 {
395380 if (file_exists ($ oldPath )) {
@@ -398,10 +383,12 @@ public function ChangeHelperClassName($oldTheme,$newTheme)
398383 return false ;
399384 }
400385 }
401- $ file = new BcFile ($ newPath );
402- $ data = $ file ->read ();
403- $ file ->write (preg_replace ('/class\s+.*?Helper/ ' , 'class ' . $ newTheme . 'Helper ' , $ data ));
404- return true ;
386+ $ file = new BcFile ($ newPath );
387+ $ data = $ file ->read ();
388+ $ tmpHelperNameSpace = preg_replace ('/namespace .+?;/ ' , 'namespace ' . $ newTheme . '\View\Helper; ' , $ data );
389+ $ helperNameSpace = preg_replace ('/class\s+.*?Helper/ ' , 'class ' . $ helperClassName , $ tmpHelperNameSpace );
390+ $ file ->write ($ helperNameSpace );
391+ return true ;
405392 }
406393
407394 /**
@@ -441,8 +428,15 @@ public function copy(string $theme): bool
441428 }
442429 BcUtil::changePluginClassName ($ oldTheme , $ newTheme );
443430 BcUtil::changePluginNameSpace ($ newTheme );
444- $ this ->ChangeHelperClassName ($ oldTheme ,$ newTheme );
445- $ this ->changeHelperNameSpace ($ newTheme );
431+
432+ $ folder = new BcFolder (BASER_THEMES . $ newTheme . DS . 'src ' . DS . 'View ' . DS . 'Helper ' );
433+ $ files = $ folder ->getFiles ();
434+
435+ foreach ($ files as $ file )
436+ {
437+ $ className = basename ($ file , '.php ' );
438+ $ this ->changeHelper ($ newTheme ,$ className );
439+ }
446440 return true ;
447441 }
448442
0 commit comments