/** * @param InputInterface $input * @param OutputInterface $output * @param Project $project * @param $target_path * @param Theme $theme * @return bool */ public function prepareTargetPath(InputInterface $input, OutputInterface $output, Project $project, $target_path, Theme $theme) { Shade::clearDir($target_path, function ($path) use(&$output) { $output->writeln("{$path} deleted"); }); Shade::copyDir($theme->getPath() . '/assets', "{$target_path}/assets", function ($path) use(&$output) { $output->writeln("{$path} copied"); }); return true; }
/** * Clear all files and subfolders from $path * * @param string $path * @param callable|null $on_item_deleted * @param bool $is_subpath */ public static function clearDir($path, $on_item_deleted = null, $is_subpath = false) { if (is_link($path)) { // Don't follow links } elseif (is_file($path)) { if (unlink($path)) { if ($on_item_deleted) { call_user_func($on_item_deleted, $path); } } } elseif (is_dir($path)) { foreach (glob(rtrim($path, '/') . '/*') as $index => $subdir_path) { Shade::clearDir($subdir_path, $on_item_deleted, true); } if ($is_subpath && rmdir($path)) { if ($on_item_deleted) { call_user_func($on_item_deleted, $path); } } } }