protected function TestSiteTearDownCommand::fileUnmanagedDeleteRecursive in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php \Drupal\TestSite\Commands\TestSiteTearDownCommand::fileUnmanagedDeleteRecursive()
- 9 core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php \Drupal\TestSite\Commands\TestSiteTearDownCommand::fileUnmanagedDeleteRecursive()
Deletes all files and directories in the specified path recursively.
Note this method has no dependencies on Drupal core to ensure that the test site can be torn down even if something in the test site is broken.
Parameters
string $path: A string containing either a URI or a file or directory path.
callable $callback: (optional) Callback function to run on each file prior to deleting it and on each directory prior to traversing it. For example, can be used to modify permissions.
Return value
bool TRUE for success or if path does not exist, FALSE in the event of an error.
See also
\Drupal\Core\File\FileSystemInterface::deleteRecursive()
File
- core/
tests/ Drupal/ TestSite/ Commands/ TestSiteTearDownCommand.php, line 115
Class
- TestSiteTearDownCommand
- Command to tear down a test Drupal site.
Namespace
Drupal\TestSite\CommandsCode
protected function fileUnmanagedDeleteRecursive($path, $callback = NULL) {
if (isset($callback)) {
call_user_func($callback, $path);
}
if (is_dir($path)) {
$dir = dir($path);
while (($entry = $dir
->read()) !== FALSE) {
if ($entry == '.' || $entry == '..') {
continue;
}
$entry_path = $path . '/' . $entry;
$this
->fileUnmanagedDeleteRecursive($entry_path, $callback);
}
$dir
->close();
return rmdir($path);
}
return unlink($path);
}