method create documentation in bbn\Ide\Directories
Creates a a new file or a new directory.
function($dir, $tab, $path, $name, $type)
{
($root = $this->getRootPath($dir))
){
$path = $path === './' ? '' : $path . '/';
$ext = bbn\Str::fileExt($name);
$default = '';
// MVC
if ( !empty($cfg['tabs']) &&
!empty($tab)
){
$cfg = $cfg['tabs'][$tab];
$root = $root . $cfg['path'];
}
// New file
if ( $type === 'file' ){
if ( !empty($ext) ){
$ext_ok = array_filter($cfg['extensions'], function($e) use ($ext){
return ( $e['ext'] === $ext );
});
if ( !empty($ext_ok) ){
$default = array_values($ext_ok)[0]['default'];
}
}
if ( empty($ext) ||
(!empty($ext) && empty($ext_ok))
){
$ext = $cfg['extensions'][0]['ext'];
$default = $cfg['extensions'][0]['default'];
}
$file = $path . bbn\Str::fileExt($name, 1)[0] . '.' . $ext;
$real = $root . $file;
if ( is_file($real) ){
return $this->error("The file already exists");
}
if ( !bbn\File\Dir::createPath(X::dirname($real)) ){
return $this->error("Impossible to create the container directory");
}
if ( !file_put_contents($real, $default) ){
return $this->error("Impossible to create the file");
}
// Add item to options table for permissions
if ( $tab === 'php' ){
if ( !$this->createPermByReal($real) ){
return $this->error("Impossible to create the option");
}
}
}
//New directory
else if ( $type === 'dir' ){
$file = $path . '/' . $name;
$real = $root . $file;
if ( is_dir($real) ){
return $this->error("The directory already exists");
}
if ( !bbn\File\Dir::createPath($real) ){
return $this->error("Impossible to create the directory");
}
}
return $file;
}
return $this->error("There is a problem in the name (dir) you entered");
}
Creates a a new file or a new directory. 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