function TestSiteTearDownCommand::fileUnmanagedDeleteRecursive

Same name in other branches
  1. 8.9.x core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php \Drupal\TestSite\Commands\TestSiteTearDownCommand::fileUnmanagedDeleteRecursive()
  2. 10 core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php \Drupal\TestSite\Commands\TestSiteTearDownCommand::fileUnmanagedDeleteRecursive()
  3. 11.x 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()

1 call to TestSiteTearDownCommand::fileUnmanagedDeleteRecursive()
TestSiteTearDownCommand::tearDown in core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php
Removes a given instance by deleting all the database tables and files.

File

core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php, line 115

Class

TestSiteTearDownCommand
Command to tear down a test Drupal site.

Namespace

Drupal\TestSite\Commands

Code

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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.