method copy documentation in bbn\Ide\Directories
Duplicates a file or a directory, MVC or not.
function($dir, $path, $name, $type, $file)
{
($root = $this->getRootPath($dir)) &&
bbn\Str::checkFilename($name)
){
$is_file = $type === 'file';
$wtype = $is_file ? 'file' : 'directory';
$path = $path === './' ? '' : $path . '/';
$bits = explode('/', $file);
// File cfg
$file_cfg = bbn\Str::fileExt(array_pop($bits), 1);
// Existing filename without its extension
$fn = $file_cfg[0];
// Existing file's extension
$fe = $file_cfg[1];
// Existing file's path
$fp = implode('/', $bits);
$files = [];
$ext = false;
// MVC
if ( !empty($cfg['tabs']) ){
foreach ( $cfg['tabs'] as $t ){
if (empty($t['fixed']) ){
if ( $is_file ){
// Check all extensions
foreach ( $t['extensions'] as $e ){
$real = $root . $t['path'] . $fp . '/' . $fn . '.' . $e['ext'];
$real_new = $root. $t['path'] . $path . $name . '.' . $e['ext'];
if( file_exists($real) ){
if ( !file_exists($real_new) ){
$files[$real] = $real_new;
$ext = empty($ext) ? $e['ext'] : $ext;
if ( $t['url'] === 'php' ){
$perms = $real_new;
}
}
else {
$this->error("The file $real_new is already exists.");
return false;
}
}
}
}
else {
$real = $root . $t['path'] . $fp . '/' . $fn;
$real_new = $root. $t['path'] . $path . $name;
if ( file_exists($real) ){
if ( !file_exists($real_new) ){
$files[$real] = $real_new;
if ( $t['url'] === 'php' ){
$perms = $real_new;
}
}
else {
$this->error("The directory $real_new is already exists.");
return false;
}
}
}
}
}
}
else {
$real = $root . $file;
$real_new = $root. $path . $name . '.' . $fe;
if ( file_exists($real) ){
if ( !file_exists($real_new) ){
$files[$real] = $real_new;
}
else {
$this->error("The $wtype $real_new is already exists.");
return false;
}
}
}
foreach ($files as $s => $d ){
if ( !file_exists(X::dirname($d)) ){
if ( !bbn\File\Dir::createPath(X::dirname($d)) ){
$this->error("Impossible to create the path $d");
return false;
}
}
if ( !bbn\File\Dir::copy($s, $d) ){
$this->error("Impossible to duplicate the $wtype: $s -> $d");
return false;
}
}
// Create permissions
if ( !empty($perms) ){
if ( $is_file ){
self::createPermByReal($perms);
}
else {
$dir_perms = function($fd) use(&$dir_perms){
foreach ( $fd as $f ){
if ( is_file($f) &&
(X::basename($f) !== '_ctrl.php')
){
self::createPermByReal($f);
}
else if ( is_dir($f) ){
$dir_perms(bbn\File\Dir::getFiles($f, 1));
}
}
};
$dir_perms(bbn\File\Dir::getFiles($perms, 1));
}
}
if ( $is_file ){
return (!empty($path) ? $path : '') . $name . '.' . (!empty($cfg['tabs']) ? $ext : $fe);
}
return true;
}
return false;
}
Duplicates a file or a directory, MVC or not. BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way
This website uses cookies to ensure you get the best experience on our website.
© 2011-2025
BBN Solutions