This commit is contained in:
2024-10-06 23:09:22 +03:00
parent d8b103fe33
commit af604aa607
9 changed files with 80 additions and 40 deletions
+24 -6
View File
@@ -9,13 +9,16 @@ $newPath = realpath($argv[1]);
$newEntity = __getModuleEntity($newPath);
$nullableEntity = __getModuleEntity(__DIR__);
function copy_folder_safe($d1, $d2, $upd = true, $force = true, $exclude = []) {
function copy_folder_safe($d1, $d2, $upd = true, $force = true, $exclude = [], $handler = null) {
$cm = 0;
str_replace($exclude, $exclude, $d1, $cm);
if($cm){
echo 'skip ' . $d1 . PHP_EOL;
return;
}
if(is_callable($handler)){
call_user_func_array($handler, [$d1, &$d2]);
}
if ( is_dir( $d1 ) ) {
$d2 = mkdir_safe( $d2, $force );
if (!$d2) {
@@ -24,7 +27,7 @@ function copy_folder_safe($d1, $d2, $upd = true, $force = true, $exclude = []) {
$d = dir( $d1 );
while ( false !== ( $entry = $d->read() ) ) {
if ( $entry != '.' && $entry != '..' )
copy_folder_safe( "$d1/$entry", "$d2/$entry", $upd, $force, $exclude);
copy_folder_safe( "$d1/$entry", "$d2/$entry", $upd, $force, $exclude, $handler);
}
$d->close();
}
@@ -61,8 +64,8 @@ function fs_log($str) {
fclose($log);
}
function _fix($newPath, ModuleEntity $newEntity, ModuleEntity $nullableEntity){
$d = new RecursiveDirectoryIterator( $newPath );
function _fix(ModuleEntity $newEntity, ModuleEntity $nullableEntity){
$d = new RecursiveDirectoryIterator( $newEntity->getPath() );
foreach( new RecursiveIteratorIterator( $d, 1 ) as $path ){
if( is_file( $path ) && str_ends_with($path, '.php')){
$orig_file = file_get_contents($path);
@@ -74,6 +77,13 @@ function _fix($newPath, ModuleEntity $newEntity, ModuleEntity $nullableEntity){
$new_file = str_replace($nullableEntity->fields()->prefix, $newEntity->fields()->prefix, $new_file, $cr);
$new_file = str_replace($nullableEntity->getNamespace(), $newEntity->getNamespace(), $new_file, $cr);
$lastModuleName = collect(explode('.', $newEntity->fields()->id))->last();
$lastNullableModuleName = collect(explode('.', $nullableEntity->fields()->id))->last();
$new_file = str_replace(ucfirst($lastNullableModuleName), ucfirst($lastModuleName), $new_file, $cr);
$new_file = str_replace(strtolower($lastNullableModuleName), strtolower($lastModuleName), $new_file, $cr);
echo $cr . ' ' .$path . PHP_EOL;
if($orig_file != $new_file){
@@ -90,5 +100,13 @@ copy_folder_safe($nullableEntity->getPath(), $newEntity->getPath(), true, true,
'.git',
'clone.php',
'.module.json',
]);
_fix($newPath, $newEntity, $nullableEntity);
], function ($d1, &$d2) use ($nullableEntity, $newEntity){
$lastModuleName = collect(explode('.', $newEntity->fields()->id))->last();
$lastNullableModuleName = collect(explode('.', $nullableEntity->fields()->id))->last();
$d2 = str_replace(ucfirst($lastNullableModuleName), ucfirst($lastModuleName), $d2, $cr);
$d2 = str_replace(strtolower($lastNullableModuleName), strtolower($lastModuleName), $d2, $cr);
});
_fix($newEntity, $nullableEntity);